Skip to content

Instantly share code, notes, and snippets.

@gautamk
Last active December 18, 2015 14:08
Show Gist options
  • Save gautamk/5794766 to your computer and use it in GitHub Desktop.
Save gautamk/5794766 to your computer and use it in GitHub Desktop.
assertEquals of Json strings by parsing into hashmaps using Jackson
private static void assertEqualsJson(String expectedJson,String actualJson){
final ObjectMapper objectMapper = new ObjectMapper();
Map<String,Object> expected = null,actual = null;
try {
expected = objectMapper.readValue(expectedJson, new TypeReference<Map<String, Object>>() {});
actual = objectMapper.readValue(actualJson, new TypeReference<Map<String, Object>>() {});
} catch (IOException e) {
e.printStackTrace();
}
try {
assertEquals(expected,actual);
} catch (AssertionError e){
throw new AssertionError("expected:<" + expectedJson +"> but was:<" + actualJson +">", e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment