fix: Add synthetic check for reflection fields

This commit is contained in:
Krrish Ghimire
2019-12-05 21:29:30 +05:45
parent 4595a00421
commit 3d909c3632
2 changed files with 6 additions and 4 deletions

Binary file not shown.

View File

@@ -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) {