ObjectMapperUtil { public String convertToString(Object object) { try { return objectMapper.writeValueAsString(object); } catch (JsonProcessingException e) { throw new RuntimeException("JSON serialization to String failed", e); } }  String convertToString(Object object); Object convertToObject(String data, TypeReference c);  }
@Test public void testConvertToString() throws JsonProcessingException { val someObj = Collections.singletonMap("foo", "bar"); val expected = new ObjectMapper().writeValueAsString(someObj); val actual = utilUnderTest.convertToString(someObj); assertEquals(expected, actual); }
@Test(expected = RuntimeException.class) public void testConvertToString_invalidObject() { utilUnderTest.convertToString(new Object()); }