JacksonUtils { public static String jsonToString(JsonNode node) { try { return node == null ? null : MAPPER.writeValueAsString(node); } catch (JsonProcessingException e) { throw new SdkClientException("Could not serialize JSON", e); } } private  JacksonUtils(); static String jsonToString(JsonNode node); static JsonNode stringToJsonNode(String paramName, String val); static JsonNode objectToJsonNode(Object val);  }
@Test public void jsonToString_NullNode_ReturnsNull() { assertNull(jsonToString(null)); }
@Test public void jsonToString_NonNullNode_ReturnsJson() throws IOException { String json = "{\"foo\": \"bar\"}"; assertJsonEquals(json, jsonToString(MAPPER.readTree(json))); }
@Test(expected = SdkClientException.class) public void invalidJsonNode_ThrowsException() throws IOException { JsonNode mock = Mockito.mock(JsonNode.class); Mockito.doThrow(new JsonMappingException("BOOM")) .when(mock).serialize(any(JsonGenerator.class), any(SerializerProvider.class)); jsonToString(mock); }