@Override @Test public void shouldCorrectlyWriteBsonObjectWithNestedObjectValue() { writer = new PrettyJsonWriter(); BasicDocument address = new BasicDocument(); address.put("street", "100 Main St."); address.put("city", "Springfield"); BasicDocument top = new BasicDocument(); top.put("firstName", "Jack"); top.put("lastName", "Riley"); top.put("address", address); String actual = writer.write(top); String expected = "{\n \"firstName\" : \"Jack\",\n \"lastName\" : \"Riley\",\n \"address\" : {\n \"street\" : \"100 Main St.\",\n \"city\" : \"Springfield\"\n }\n}"; assertSame(expected, actual); }
@Override protected void write(Document bson, Writer writer) throws IOException { if (bson.size() == 0) { writer.append("{ }"); return; } ++depth; writer.append('{').append('\n'); indent(writer); Iterator<Field> iter = bson.fields().iterator(); if (iter.hasNext()) { write(iter.next(), writer); while (iter.hasNext()) { writer.append(',').append('\n'); indent(writer); write(iter.next(), writer); } } writer.append('\n'); --depth; indent(writer); writer.append('}'); }
PrettyJsonWriter extends CompactJsonWriter { @Override protected void write(Document bson, Writer writer) throws IOException { if (bson.size() == 0) { writer.append("{ }"); return; } ++depth; writer.append('{').append('\n'); indent(writer); Iterator<Field> iter = bson.fields().iterator(); if (iter.hasNext()) { write(iter.next(), writer); while (iter.hasNext()) { writer.append(',').append('\n'); indent(writer); write(iter.next(), writer); } } writer.append('\n'); --depth; indent(writer); writer.append('}'); } }
PrettyJsonWriter extends CompactJsonWriter { @Override protected void write(Document bson, Writer writer) throws IOException { if (bson.size() == 0) { writer.append("{ }"); return; } ++depth; writer.append('{').append('\n'); indent(writer); Iterator<Field> iter = bson.fields().iterator(); if (iter.hasNext()) { write(iter.next(), writer); while (iter.hasNext()) { writer.append(',').append('\n'); indent(writer); write(iter.next(), writer); } } writer.append('\n'); --depth; indent(writer); writer.append('}'); }  }
PrettyJsonWriter extends CompactJsonWriter { @Override protected void write(Document bson, Writer writer) throws IOException { if (bson.size() == 0) { writer.append("{ }"); return; } ++depth; writer.append('{').append('\n'); indent(writer); Iterator<Field> iter = bson.fields().iterator(); if (iter.hasNext()) { write(iter.next(), writer); while (iter.hasNext()) { writer.append(',').append('\n'); indent(writer); write(iter.next(), writer); } } writer.append('\n'); --depth; indent(writer); writer.append('}'); }   }
PrettyJsonWriter extends CompactJsonWriter { @Override protected void write(Document bson, Writer writer) throws IOException { if (bson.size() == 0) { writer.append("{ }"); return; } ++depth; writer.append('{').append('\n'); indent(writer); Iterator<Field> iter = bson.fields().iterator(); if (iter.hasNext()) { write(iter.next(), writer); while (iter.hasNext()) { writer.append(',').append('\n'); indent(writer); write(iter.next(), writer); } } writer.append('\n'); --depth; indent(writer); writer.append('}'); }    }