class 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('}');
   }

}