Here you can find the source of toJson(final Document doc)
public static String toJson(final Document doc)
//package com.java2s; //License from project: Apache License import org.bson.Document; import org.bson.json.JsonMode; import org.bson.json.JsonWriterSettings; public class Main { public static String toJson(final Document doc) { return toJson(doc, false); }/*from w w w .j a v a 2 s. com*/ public static String toJson(final Document doc, boolean pretty) { return doc.toJson(new JsonWriterSettings(JsonMode.SHELL, pretty)); } }