[JAVA-1929] Add parse factory method to BsonArray Created: 20/Aug/15  Updated: 27/Nov/16  Resolved: 06/Oct/16

Status: Closed
Project: Java Driver
Component/s: JSON
Affects Version/s: None
Fix Version/s: 3.4.0-rc1, 3.4.0

Type: New Feature Priority: Minor - P4
Reporter: Andrew Ryder (Inactive) Assignee: Jeffrey Yemin
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related

 Description   

It would be handy if JSON parsing facilities in the Java driver existed that used compatible types with the collection/database methods that take BSON parameters.

Notably, parsing a JSON string to pass to the "aggregate" method requires some fiddling to bring the two APIs into alignment. This same condition arises in a few other places wherever something other than BsonDocument is required.

To go from a JSON string to something which can be passed to the aggregate method, for example, requires this rather unwieldy extra step:

BsonArray array = new BsonArrayCodec(MongoClient.getDefaultCodecRegistry())
        .decode(new JsonReader(myJsonString), DecoderContext.builder().build());

This ticket is to request the implementation of some intuitive utility methods to bridge the gap. Perhaps directly in the JSON class.



 Comments   
Comment by Githook User [ 06/Oct/16 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: JAVA-1929: Add static parse method to BsonArray
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/2b36e3e91a49e8ef9f6ccc12235f02623060010b

Comment by Jeffrey Yemin [ 20/Aug/15 ]

Perhaps something like:

BsonArray array = BsonArray.parse(myJsonString);

to go along with the existing:

BsonDocument document = BsonDocument.parse(myJsonString);

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