Mongo Java: How to serialize DBObject as JSON on file?

java, json, mongo-java, mongodb

Solution

It seems that BasicDBObject's toString() method returns the JSON serialization of the object.

Problem

I have a document in `MongoDB` as ``` name: name date_created: date p_vars: { 01: { a: a, b: b, } 02: { a: a, b: b, } .... } ``` represented as `DBObject` - All `key`, `value` pairs are of type `String` - I want to serialize this document using Java, Looking at the api, I did not find anything, How can I serialize a `DBObject` as `JSON` on file?

Original source