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. 10
      src/np/com/krrish/Mapper.java

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

Binary file not shown.

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

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

Loading…
Cancel
Save