JsonUtils { public static int compare(JsonNode left, JsonNode right) { if (left.isLong() || left.isInt()) { return Long.compare(left.asLong(), right.asLong()); } else if (left.isDouble() || left.isFloat()) { return Double.compare(left.asDouble(), right.asDouble()); } else if (left.isTextual()) { return left.asText().compareTo(right.asText()); } else if (left.isBoolean()) { return Boolean.compare(left.asBoolean(), right.asBoolean()); } return left.equals(right) ? 0 : -1; } private  JsonUtils(); static ObjectNode createObjectNode(); static JsonNode decode(String input); static JsonNode decode(String input, boolean failQuietly); static ArrayNode createArrayNode(); static ObjectMapper getMapper(); static int compare(JsonNode left, JsonNode right);  }
@Test public void testJsonCompare() { assertEquals(JsonUtils.compare(json(1), json(1)), 0); assertEquals(JsonUtils.compare(json(1), json(2)), -1); assertEquals(JsonUtils.compare(json(2), json(1)), 1); assertEquals(JsonUtils.compare(json(1.0), json(1.0)), 0); assertEquals(JsonUtils.compare(json(1.0), json(2.0)), -1); assertEquals(JsonUtils.compare(json(2.0), json(1.0)), 1); assertEquals(JsonUtils.compare(json("a"), json("a")), 0); assertEquals(JsonUtils.compare(json("a"), json("b")), -1); assertEquals(JsonUtils.compare(json("b"), json("a")), 1); assertEquals(JsonUtils.compare(BooleanNode.TRUE, BooleanNode.TRUE), 0); assertEquals(JsonUtils.compare(BooleanNode.FALSE, BooleanNode.FALSE), 0); assertEquals(JsonUtils.compare(BooleanNode.TRUE, json("true")), 0); assertEquals(JsonUtils.compare(BooleanNode.FALSE, json("false")), 0); assertEquals(JsonUtils.compare(BooleanNode.TRUE, BooleanNode.FALSE), 1); assertEquals(JsonUtils.compare(BooleanNode.FALSE, BooleanNode.TRUE), -1); }