[JAVA-709] com.mongodb.util.JSON should provide JSON#serialize( Object o, Writer writer) and JSON#serialize( Object o, OutputStream out) to have a better support for streaming Created: 08/Dec/12 Updated: 31/Jan/18 Resolved: 31/Jan/18 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | API |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | Angelo | Assignee: | Unassigned |
| Resolution: | Won't Fix | Votes: | 2 |
| Labels: | driver | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
| Description |
|
To serialize a BasicDBObject to a JSON content, it uses the https://github.com/mongodb/mongo-java-driver/blob/master/src/main/com/mongodb/util/JSON.java which provides the JSON#serialize( Object o, StringBuilder buf). IMHO, I think it should be better to provides 2 methods with Writer and OutputStream:
Why? Because if you wish returns the JSON content from a Servlet (HttpServletResponse#getWriter(), HttpServletResponse#getOutputStream()), we cannot use streaming mode. We need to create a StringBuilder and put it to the http response writer or outpustream : ------------------------------------------------------- I think it should be better to do with streaming mode like this: ------------------------------------------------------- |
| Comments |
| Comment by Jeffrey Yemin [ 31/Jan/18 ] |
|
The com.mongodb.util.JSON class is deprecated, so we won't be expanding its API. Please note that the JsonWriter class which has replaced it does take a Writer. |
| Comment by Angelo [ 17/Dec/12 ] |
|
By waiting for your decision, I have created mongo-jee project and I have putted my code on Git at https://github.com/angelozerr/mongo-jee/tree/master/src/main/java/com/mongodb/jee/util |
| Comment by Angelo [ 17/Dec/12 ] |
|
I have modified source of 2.10.1 to manage streaming with JSON.serialize which provides 2 methods :
Note that I have changed the package to com.mongodb.jee.util to have none conflict with my JEE support for MongoDB and your driver. I'm using this JSON serialize methods with Servlet (Writer) and JAX-RS MessageBodyWriter. |
| Comment by Angelo [ 15/Dec/12 ] |
|
It seems this issue is similat than https://jira.mongodb.org/browse/JAVA-104 |