EntityFactory { static String getBodyAsString(@Nullable Object body) { try { return (body instanceof String) ? (String) body : RestClientFactory.getObjectMapper().writeValueAsString(body); } catch (JsonProcessingException e) { throw new IllegalArgumentException("Unable to process JSON body", e); } }    }
@Test public void getBodyAsString() { Record r = new Record(7, "foo"); String bodyAsString = EntityFactory.getBodyAsString(r); assertEquals("{\"i\":7,\"s\":\"foo\"}", bodyAsString); }
@Test public void getBodyAsString_String() { String input = "{}"; String bodyAsString = EntityFactory.getBodyAsString(input); assertEquals(input, bodyAsString); }