I am working on testing that allow matching request and response JSON objects. I use objectmapper to convert object to JSON. Then, I use the same way to convert response JSON to object by readValue() method. However, I get the wrong result on only one of them.
Below is the example of the comparing. On test2, it contains an extra space after converting the JSON object into the object. I have no idea how that extra space come from since I am sure the value doesn't contain space.
expected:<TestObject(test1=t, test2=t, test3=t)>
but was:<TestObject(test1=t, test2=t , test3=t)>
Have you tried using Jackson to compare your JSON objects?
ObjectMapper mapper = new ObjectMapper();
JsonNode json1 = mapper.readTree(json_string_1);
JsonNode json2 = mapper.readTree(json_string_2);
assertEquals(json1, json2);