JsonEnvelopeWriter { public static String writeJsonObject(final JsonObject json) { final StringWriter stringWriter = new StringWriter(); try (final JsonWriter jsonWriter = writerFactory.createWriter(stringWriter)) { jsonWriter.writeObject(json); return stringWriter.toString(); } } private  JsonEnvelopeWriter(); static String writeJsonObject(final JsonObject json);  }
@Test public void shouldWriteAJsonObjectAsAPrettyPrintedString() throws Exception { final JsonObject jsonObject = createObjectBuilder() .add("aProperty", "value a") .add("bProperty", "value b") .add("cProperty", "value c") .add("anObject", createObjectBuilder() .add("innerProperty", "innerValue")) .build(); final String json = JsonEnvelopeWriter.writeJsonObject(jsonObject); assertThat(json, is(EXPECTED_JSON)); }