Browse Source

fix: Add synthetic check for reflection fields

master
Krrish Ghimire 5 years ago
parent
commit
3d909c3632
  1. BIN
      build/libs/mapper-1.0-SNAPSHOT.jar
  2. 2
      src/np/com/krrish/Mapper.java

BIN
build/libs/mapper-1.0-SNAPSHOT.jar

Binary file not shown.

2
src/np/com/krrish/Mapper.java

@ -10,11 +10,13 @@ public class Mapper {
object = aClass.getConstructor().newInstance(); object = aClass.getConstructor().newInstance();
Field[] sourceFields = source.getClass().getDeclaredFields(); Field[] sourceFields = source.getClass().getDeclaredFields();
for (Field sourceField : sourceFields) { for (Field sourceField : sourceFields) {
if (!sourceField.isSynthetic()) {
sourceField.setAccessible(true); sourceField.setAccessible(true);
Field destinationField = object.getClass().getDeclaredField(sourceField.getName()); Field destinationField = object.getClass().getDeclaredField(sourceField.getName());
destinationField.setAccessible(true); destinationField.setAccessible(true);
destinationField.set(object, sourceField.get(source)); destinationField.set(object, sourceField.get(source));
} }
}
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
e.printStackTrace(); e.printStackTrace();
} catch (NoSuchFieldException ignored) { } catch (NoSuchFieldException ignored) {

Loading…
Cancel
Save