@Override
public void merge(T prev, T curr, ReflectiveConfig config, ConfigWriter diffwriter, Field field) throws ConfigurationException {
// if this object is a property, get a child
if (field != null && field.getType().equals(clazz)) {
ConfigField fieldAnno = (ConfigField) field.getAnnotation(ConfigField.class);
if (prev == null) {
write(serialize(curr, config, field), config, diffwriter, field);
return;
} else
if (curr == null) {
diffwriter.getChildWriter(fieldAnno.name(), field).removeCurrentNode();
return;
}
diffwriter = diffwriter.getChildWriter(fieldAnno.name(), field);
}
// look through all fields of the config class, not including
// superclass fields
for (Field classField : clazz.getDeclaredFields()) {
// if field is not annotated, skip it
ConfigField fieldAnno = (ConfigField) classField.getAnnotation(ConfigField.class);
if (fieldAnno == null)
continue;
try {
Object prevProp = PropertyUtils.getSimpleProperty(prev, classField.getName());
Object currProp = PropertyUtils.getSimpleProperty(curr, classField.getName());
// find adapter
ConfigTypeAdapter customRep = config.lookupTypeAdapter(classField.getType());
customRep.merge(prevProp, currProp, config, diffwriter, classField);
} catch (Exception e) {
throw new ConfigurationException("Cannot store diff for field " + fieldAnno.name(), e);
}
}
// do actual merge