I'm using java-object-diff to get differences between two objects parsed from xml by JAXB. In below example, I'm using the same string to test if I get no differences, however log.info("has changes: " + diff5.hasChanges());
logs true
.
JAXBContext context1 = JAXBContext.newInstance(Item.class);
Unmarshaller m1 = context1.createUnmarshaller();
Item base = (Item) m1.unmarshal(new StringReader(s));
Item working = (Item) m1.unmarshal(new StringReader(s));
DiffNode diff5 = ObjectDifferBuilder
.buildDefault()
.compare(working, base);
log.info("has changes: " + diff5.hasChanges());
diff5.visit((node, visit) -> {
final Object baseValue = node.canonicalGet(base);
final Object workingValue = node.canonicalGet(working);
final String message = node.getPath() + " changed from " +
baseValue + " to " + workingValue;
System.out.println(message);
});
The message I get from System.out.println is always the same, saying it has changed from null
to <the actual value>
This happens for every property. E.g.
content changed from null to Mit dem Wasserinonisator
I have verified that the both Items
have the same content and none of the both actualy is not null
, but the exact same content.
Item
is a pojo with many subclasses (all getters and setters are present), e.g.
public class Item {
@XmlElement(name = "ASIN", required = true)
protected String asin;
@XmlElement(name = "ParentASIN")
protected String parentASIN;
@XmlElement(name = "Errors")
protected Errors errors;
@XmlElement(name = "DetailPageURL")
protected String detailPageURL;
@XmlElement(name = "ItemLinks")
protected ItemLinks itemLinks;
@XmlElement(name = "SalesRank")
protected String salesRank;
@XmlElement(name = "SmallImage")
protected Image smallImage;
}
Is there any way to make java-object-diff work, to make it compare the values correctly?