### Question:
JsonObjectImpl extends AbstractMap<String, JsonValue> implements JsonObject, Serializable { @Override public String toString() { if (unmodifieableBackingMap.isEmpty()) { return "{}"; } final StringWriter writer = new StringWriter(); try (final JsonGenerator generator = new JsonGeneratorImpl(writer, provider, false)) { generator.writeStartObject(); unmodifieableBackingMap.forEach(generator::write); generator.writeEnd(); } return writer.toString(); } JsonObjectImpl(final Map<String, JsonValue> backingMap, final BufferStrategy.BufferProvider<char[]> provider); @Override JsonArray getJsonArray(final String name); @Override JsonObject getJsonObject(final String name); @Override JsonNumber getJsonNumber(final String name); @Override JsonString getJsonString(final String name); @Override String getString(final String name); @Override String getString(final String name, final String defaultValue); @Override int getInt(final String name); @Override int getInt(final String name, final int defaultValue); @Override boolean getBoolean(final String name); @Override boolean getBoolean(final String name, final boolean defaultValue); @Override boolean isNull(final String name); @Override ValueType getValueType(); @Override String toString(); @Override boolean equals(final Object obj); @Override int hashCode(); @Override Set<java.util.Map.Entry<String, JsonValue>> entrySet(); @Override void clear(); @Override JsonValue remove(final Object key);  }### Answer:
@Test public void reuseObjectBuilder() { final JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder(); final JsonArrayBuilder jsonArrayBuilder = Json.createArrayBuilder(); IntStream.range(1, 10).forEach(numer -> { jsonObjectBuilder.add("key", String.format("Key %d", numer)); jsonObjectBuilder.add("value", String.format("Value %d", numer)); jsonArrayBuilder.add(jsonObjectBuilder); }); final String message = jsonArrayBuilder.build().toString(); assertEquals("[{\"key\":\"Key 1\",\"value\":\"Value 1\"},{\"key\":\"Key 2\",\"value\":\"Value 2\"}," + "{\"key\":\"Key 3\",\"value\":\"Value 3\"},{\"key\":\"Key 4\",\"value\":\"Value 4\"},{\"key\":\"Key " + "5\",\"value\":\"Value 5\"},{\"key\":\"Key 6\",\"value\":\"Value 6\"},{\"key\":\"Key 7\"," + "\"value\":\"Value 7\"},{\"key\":\"Key 8\",\"value\":\"Value 8\"},{\"key\":\"Key 9\"," + "\"value\":\"Value 9\"}]", message); }
@Test public void objectToString() { final JsonObjectBuilder ob = Json.createObjectBuilder(); ob.add("a", new JsonStringImpl("b")); assertEquals("{\"a\":\"b\"}", ob.build().toString()); }
@Test public void testToStringShouldReturnEscapedKey() { final JsonObjectBuilder ob = Json.createObjectBuilder(); ob.add("foo\"bar", new JsonLongImpl(42)); assertEquals("{\"foo\\\"bar\":42}", ob.build().toString()); }
@Test public void testToStringShouldReturnEscapedValue() { final JsonObjectBuilder ob = Json.createObjectBuilder(); ob.add("a", new JsonStringImpl("foo\"bar")); assertEquals("{\"a\":\"foo\\\"bar\"}", ob.build().toString()); }