Last active
December 18, 2015 14:08
-
-
Save gautamk/5794766 to your computer and use it in GitHub Desktop.
assertEquals of Json strings by parsing
into hashmaps using Jackson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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