title: Bson - How to convert JSON to List<Document> and List<Document> to JSON?
body: <p>I'm using Java Driver 3.0 with MongoDB in order to send JSONs through a webservice. </p>
  
  <p>When I want to convert a Document object (org.bson.Document) to JSON, I use <code>obj.toJson()</code>, and when I want to convert a JSON to a Document object, I use <code>Document.parse(json)</code>.</p>
  
  <p>However when I'm dealing with lists of Documents (represented like this in JSON:<code>[{"field1":1, ...}, {"field1":2, ...}]</code>), I can't figure out a clean way of doing these conversions.</p>
  
  <p>So far, I've come up with these "hacks":</p>
  
  <ul>
  <li><p>From List to JSON: I add the list of documents as a value of a field called "list" in a bigger document. I convert this big document to JSON, and remove what I don't need from the obtained String.</p>
  
  <pre><code>public String toJson(List&lt;Document&gt; docs){
      Document doc = new Document("list", docs);
      String json = doc.toJson();
      return json.substring(json.indexOf(":")+2, json.length()-1);
  }
  </code></pre></li>
  <li><p>From JSON to List: I do the opposite by adding this "list" field to the JSON, converting it to a Document and getting only the value of this field from the Document.</p>
  
  <pre><code>public static List&lt;Document&gt; toListOfDocuments(String json){
      Document doc = Document.parse("{ \"list\":"+json+"}");
      Object list = doc.get("list");
      if(list instanceof List&lt;?&gt;) {
          return (List&lt;Document&gt;) doc.get("list");
      }
      return null ;
  }
  </code></pre></li>
  </ul>
  
  <p>I also tried to use another JSON serializer (I took Google's one), but it doesn't give the same result as the built-in <code>toJson()</code> method from the Document object, particularly for the "_id" field or the timestamps.</p>
  
  <p>Is there any clean way of doing this?</p>