I am trying to learn JUnit and I have been practicing it for some time now I have a problem in comparing 2 objects. That is think of it as JSON objects. I am using GSON for this purpose
For example, I have a JSON string and I have converted it into an object and I have another JSON object which will be exactly the same, now when I write assertEquals
for these 2 objects it's returning something like
java.lang.AssertionError:
Expected :Data@2ret9593
Actual :Data@7647qe21
As they are JSON objects the order of the key-value pairs may differ but I want it to check them and return the result if they are equal or not and ignore some fields whose values are not considered but the field is important like timestamp or dynamically generated id etc.
It's not just about equal method What I was trying here I to compare 2 JSON strings and ignore some fields that are dynamically allocated while testing
For example:
{"name": "ray", "age": "20"} == {"age": "20", "name": "ray", "timestamp": 03:10:54}
Is there any way to achieve what I want?