JsonXor { public static JsonNode xor(File original, File changed) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); ObjectNode originalTree = (ObjectNode) objectMapper.readTree(original); ObjectNode changedTree = (ObjectNode) objectMapper.readTree(changed); return xor(originalTree, changedTree); }  static JsonNode xor(File original, File changed); static JsonNode xor(InputStream original, InputStream changed);  }
@Test public void xor() throws Exception { InputStream original = JsonXorTest.class.getClassLoader().getResourceAsStream("xor/original.json"); InputStream changed = JsonXorTest.class.getClassLoader().getResourceAsStream("xor/changed.json"); String expected = getResource("xor/xored.json"); ObjectNode actual = (ObjectNode)JsonXor.xor(original, changed); JSONAssert.assertEquals(expected.toString(), actual.toString(), true); }
@Test public void xorNoDiff() throws Exception { InputStream original = JsonXorTest.class.getClassLoader().getResourceAsStream("xor/original.json"); InputStream changed = JsonXorTest.class.getClassLoader().getResourceAsStream("xor/changed-no-diff.json"); String expected = getResource("xor/xored-no-diff.json"); String actual = JsonXor.xor(original, changed).toString(); JSONAssert.assertEquals(expected, actual, true); }