I am receiving input from my Ext JS application on the front end and I want to compare two records on the java side, the record prior to a form update on the UI side and the record after setting all the new values. I have made two references to the same type of object, one before setting new values (oldRecord
) and one after (newRecord
) and compare these but when I try to use oldRecord.getClass()
on the old record it will show the new field values. Is there any way to have access to the old values? I also tried making two field arrays and passing those into my method.
private static Map<String, List<String>> changes;
public static <T> Map<String, List<String>> getChanges (T oldRecord, T newRecord) {
changes = new HashMap<String, List<String>>();
try {
if(oldRecord instanceof UserInfo && oldRecord.getClass().equals(newRecord.getClass())) {
Field field = oldRecord.getClass().getDeclaredField("name");
field.setAccessible(true);
System.out.println(field.get(oldRecord));
field = newRecord.getClass().getDeclaredField("name");
field.setAccessible(true);
System.out.println(field.get(newRecord));
// will loop through all fields in both records and compare
}
} catch (Exception e) {
System.err.println("Exception");
}
return changes;
}