I am trying to compare two JSON Strings for equality. I found this solution which uses Jackson as shown below but in all my project I am using GSON so I need to do the same thing using GSON.
ObjectMapper mapper = new ObjectMapper();
JsonNode tree1 = mapper.readTree(jsonString1);
JsonNode tree2 = mapper.readTree(jsonString2);
if (tree1.equals(tree2)) {
// yes, contents are equal -- note, ordering of arrays matters, objects not
} else {
// not equal
}
Is there any way to compare two JSON String for equality using GSON?