[JAVA-2433] JsonReader module chokes on int $type for binary extended json Created: 26/Jan/17  Updated: 10/Mar/17  Resolved: 10/Mar/17

Status: Closed
Project: Java Driver
Component/s: JSON
Affects Version/s: 3.0.0
Fix Version/s: 3.5.0

Type: Improvement Priority: Major - P3
Reporter: Chris Vogt Assignee: Jeffrey Yemin
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible

 Description   

There are two extended json parsers in the mongo-java-driver project. One in the driver module, one in the bson module. The one in the driver itself only supports the $type field of the binary extended json representation to be an integer. There is an unreleased patch in master that also allows the hex representation:

https://github.com/mongodb/mongo-java-driver/commit/600a37703ed6b4ad41bfab969a8efcbd51a00c6e#diff-71878e8b11c0d2fd1c3df294dc915e31

The JsonReader parser in the bson module however ONLY supports the hex representation as can be seen in https://github.com/mongodb/mongo-java-driver/blob/c610f1853a4a3e9e5762e196adb076b647f418ac/bson/src/main/org/bson/json/JsonReader.java#L903

This means those to parsers are currently incompatible in their released forms. You can't create an extended json representation that works with both.

The com.mongodb.util.JSON parser chokes on

{ "$binary": "YWzDtmhh", "$type": "0" }

(until the next release).

The JsonReader parser in the bson module chokes on

{ "$binary": "YWzDtmhh", "$type": 0 }.

The JsonReader parser should be fixed to also support the int representation.

We are using both mongo-scala-driver and mongo-java-driver in our project, so we currently have a problem with this.



 Comments   
Comment by Githook User [ 10/Mar/17 ]

Author:

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

Message: JAVA-2433: To improve compatibility with JSON texts generated by com.mongodb.util.JSON, handle numeric value for $type when parsing Extended JSON for binary values
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/691c7d994be4e778aff5c39330c6e56a2ae46c80

Comment by Chris Vogt [ 27/Jan/17 ]

awesome, looking forward to that, thx

Comment by Jeffrey Yemin [ 27/Jan/17 ]

OK, we'll consider adding this in order to improve interoperability between com.mongodb.util.JSON and JsonReader.

Comment by Chris Vogt [ 27/Jan/17 ]

Jeff, that's the unreleased fix for the mongo java driver json parser I mentioned. Thank you for linking the corresponding JIRA issue. That fix would indeed lead to both parsers being compatible with the hex representation and unblock us for now. I think the JsonReader module should still be fixed to support the integer type, because it has the risk to block us in the future as it prevents the mongo scala driver (and other consumers of the BSON package) from reading that representation should some producer hand it to us.

Comment by Jeffrey Yemin [ 26/Jan/17 ]

It sounds like you're asking for the two parsers to be compatible for the BSON binary type, not specifically that both parsers support the integer representation of the type. If that's the case, will JAVA-1796 unblock you?

Comment by Jeffrey Yemin [ 26/Jan/17 ]

Updated the description based on the previous comment

Comment by Chris Vogt [ 26/Jan/17 ]

correction (as I don't see how to edit)

The BSON parser chokes on

{ "$binary": "YWzDtmhh", "$type": 0 }
Generated at Thu Feb 08 08:57:12 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.