[JAVA-104] Support for streams in com.mongodb.util.JSON Created: 14/Apr/10  Updated: 21/Sep/16  Resolved: 21/Sep/16

Status: Closed
Project: Java Driver
Component/s: API
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Minor - P4
Reporter: William Shulman Assignee: Unassigned
Resolution: Won't Fix Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Java Source File EJSON.java     Java Source File EJSONParseException.java    

 Description   

It would be nice if the JSON class supported streams in addition to strings as sources and targets for JSON during parsing and serialization. In particular, I am interested in providing JSON forms to the parser via an InputStream for situations where (a) the JSON objects are very large and more importantly (b) for situations where you want to parse JSON forms from a source one after the other (i.e. a file with a series of JSON forms one after the other). It would be nice if I could create a parser object, provide it with an Input Stream, and then call parse() repeatedly, with the parser parsing and consuming from the stream one JSON object per call.

Supporting serialization to OutputStreams would be for symmetry, but also useful for similar reasons.



 Comments   
Comment by Jeffrey Yemin [ 21/Sep/16 ]

New development for JSON is being done in the JsonReader and JsonWriter classes. We won't be enhancing com.mongodb.util.JSON.

Comment by Aleksey Vorona [ 22/Oct/10 ]

Attached is the class I use in my project to parse JSON streams.

If this code is useful to MongoDB developers, you are free to use it.

This parser is based on MongoDB default JSON parser, but it differs:
1. it tolerates unquoted strings
2. it accepts both single and double quoted string
3. It uses checked exceptions wherever possible (for better error handling).
4. It supports multiple JSON entities in input stream.
5. error doesn't have offending character pointer (though it tries to print incorrect object from the beginning).

Feel free to contact me if you want me to improve this code or merge it to MongoDB Java driver source tree.

Generated at Thu Feb 08 08:51:31 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.