1

As it turns out Jackson does not do stable JSON object comparison contrary to this question. So I was wondering if GSON has stable comparison of JSON objects. (without having to override equals/implement one's own comparator)

Community
  • 1
  • 1
Kreisquadratur
  • 999
  • 8
  • 26

1 Answers1

2

Your gist shows org.json code, not Jackson.

Jackson has a perfectly able .equals() implementation for all JsonNodes. And that includes all "non container types" as well as "container types":

final JsonNodeFactory factory = JsonNodeFactory.instance;

final JsonNode node1 = factory.objectNode().put("hello", "world");
final JsonNode node2 = factory.objectNode().put("hello", "world");

node1.equals(node2); // true

Of course, it does respect JSON's "order does not matter" with object members: { "a": 1, "b": 2 } is equal to { "b": 2, "a": 1 } -- as it should.


That may only be my opinion as well, but really, when it comes to JSON, anything is better than org.json.

fge
  • 119,121
  • 33
  • 254
  • 329