Already referred few question here and there.
Use Case -
1.) Given any Two objects
, compare
both of them property by property.
2.) It will contains Collections
also, now compare collections of both the objects, now inside collection same data can be upside down, meaning say i have List<Address>
, it contains two entries in both (say Residential Address
, Office Address
), but in both list the data may be at different indexes.
3.) Need to create 3rd Object
of same type, with similar data copied, and properties set to null with different data.
4.) It might have reference classes as well.
I tired many solutions but stuck somewhere or the other, i am thinking of writing some generic solution. Though of generating two xml's
out of the two objects and then comparing node by node, but just want to get more options.
Or How much Java reflection
is stronger in this case.
answer to @markspace question.
To access a
private field
you will need to call theClass.getDeclaredField(String name)
orClass.getDeclaredFields()
method. The methodsClass.getField(String name)
andClass.getFields()
methods onlyreturn public fields
, so they won't work.To access a
private method
you will need to call theClass.getDeclaredMethod(String name, Class[] parameterTypes)
orClass.getDeclaredMethods()
method. The methodsClass.getMethod(String name, Class[] parameterTypes)
andClass.getMethods()
methods onlyreturn public methods
.XMLUnit
will work, it compares the list references recursively, also it has option to exclude fields which you do not wish to compare.RecursiveElementNameAndTextQualifier