ObjectMapperUtil { public Object convertToObject(String data, TypeReference c) { try { return objectMapper.readValue(data, c); } catch (IOException e) { throw new RuntimeException("JSON deserialization failed", e); } }  String convertToString(Object object); Object convertToObject(String data, TypeReference c);  }
@Test public void testConvertToObject() throws JsonProcessingException { val someJson = "{ \"foo\" : \"bar\" }"; val expected = new ObjectMapper().readValue(someJson, MAP_TYPE_REFERENCE); val actual = utilUnderTest.convertToObject(someJson, MAP_TYPE_REFERENCE); assertEquals(expected, actual); }
@Test(expected = RuntimeException.class) public void testConvertToObject_invalidJson() { utilUnderTest.convertToObject("", MAP_TYPE_REFERENCE); }