Why is root marked as changed?
denov opened this issue · 1 comments
denov commented
I'm trying to compare a couple DTO that's mostly Strings, longs, and a couple List<> of other DTOs. I'm only expecting to '/titleText' see be outputted and not '/'. All my DTOs have full equals() and hash() methods.
@Test
public void compareReferences() {
ReferenceDTO ref1 = getReferenceDTO("test 1");
ReferenceDTO ref2 = getReferenceDTO("test 2");
DiffNode diff = ObjectDifferBuilder.buildDefault().compare(ref1, ref2);
assertThat(diff.hasChanges(), is(true));
diff.visit((node, visit) -> System.out.println(node.getPath() + " => " + node.getState()));
System.out.println("\n---\n");
diff.visit((node, visit) -> {
final Object baseValue = node.canonicalGet(ref1);
final Object workingValue = node.canonicalGet(ref2);
final String message = node.getPath() + " changed from " + baseValue + " to " + workingValue;
System.out.println(message);
});
}
public ReferenceDTO getReferenceDTO(String titleText) {
ReferenceDTO reference = new ReferenceDTO();
reference.titleText = titleText;
return reference;
}
/ => CHANGED
/titleText => CHANGED
/ changed from org.magic.web.dto.reference.ReferenceDTO@565f390[referenceId=,sectionId=,order=,shortName=,titleText=test] to org.magic.web.dto.reference.ReferenceDTO@7dc3712[referenceId=,sectionId=,order=,shortName=,titleText=test 2]
/titleText changed from test to test 2
denov commented
I figured it out. I missed this part in the getting started page.
if (node.hasChanges() && !node.hasChildren()) { }