I am trying compare two json string with mixed elements in array. I found many answers(1,2) how compare two json but not with array. You can help me?
My code:
Passed
@Test
public void test() throws IOException {
ObjectMapper mapper = new ObjectMapper();
JsonNode node1 = mapper.readTree("{\"a\" : [{\"a\" : 2},{\"s\" : 5}], \"b\" : 2}");
JsonNode node2 = mapper.readTree("{\"b\" : 2, \"a\" : [{\"a\" : 2},{\"s\" : 5}]}");
assertThat(node1.equals(node2), is(true));
}
Failed, but why? How can compare json?
@Test
public void test() throws IOException {
ObjectMapper mapper = new ObjectMapper();
JsonNode node1 = mapper.readTree("{\"a\" : [{\"a\" : 2},{\"s\" : 5}], \"b\" : 2}");
JsonNode node2 = mapper.readTree("{\"b\" : 2, \"a\" : [{\"s\" : 5},{\"a\" : 2}]}");
assertThat(node1.equals(node2), is(true));
}
Thanks.