-
Type: Task
-
Resolution: Done
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: JSON
-
None
Sort of naive approach to get the point across.
MongoCursor<Document> cursor = ((MongoCollection)data).find().iterator(); try { response.getWriter().write("["); while (cursor.hasNext()) { response.getWriter().write(cursor.next().toJson() + (cursor.hasNext() ? "," : "")); } response.getWriter().write("]"); } finally { cursor.close(); }
// applying some json techniques MongoCursor<Document> cursor = ((MongoCollection)data).find().iterator(); JsonWriter jsonWriter = new JsonWriter(response.getWriter()); jsonWriter.writeStartDocument(); jsonWriter.writeStartArray(); while(cursor.hasNext()) { jsonWriter.writeStartDocument(); jsonWriter.writeString(cursor.next().toJson()); jsonWriter.writeEndDocument(); } jsonWriter.writeEndArray(); jsonWriter.writeEndDocument(); cursor.close();
Please guide for the write way to serialize collections to JSON.