I need to compare two instances of the same java class and obtain the list of variables that are not equals.
Let's say i have this kind of java class
public class DummyClass
{
private String name;
private String surname;
[constructors, getters and setters ...]
}
At runtime I have 2 instances of DummyClass, let's say a = ["foo", "bar"] and b = ["foo", "rab"], so with same names but different surnames. My goal is to compare them and hilight the fact that a.surname is not equals to b.surname, and also give as output something that sounds more or less like "field not equals: surname, values found a.surname = 'bar' - b.surname = 'rab'" I have too many classes, can't override the compareTo into each one of them, so as first approach i randomly landed on xmlunit --> great! perfect! it offer exactly what I need IF I start from two xml files, so I tought to use JAXB for the mapping class - to - xml but with Java 17 I can't use JAXB, and I can't switch to previous version of Java.
Is there any workaround to do what XMLUNIT does? XML approach was just an idea, i can use whatever does the job.
Here is one way using just Java.
Create some instances to evaluate.
prints