[JAVA-1796] JSON.parse method doesn't support $type in $binary where type is a hexadecimal string Created: 04/May/15  Updated: 06/Feb/19  Resolved: 06/Dec/16

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: William Delanoue Assignee: Ross Lawley
Resolution: Done Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Case:

 Description   

Hi,

as discussed on https://groups.google.com/d/msg/mongodb-user/ihCV6zWzWlg/u7Q-AKxBEQEJ

The old "Json" package doesn't support the Extended JSON :

$type is not a String but an Integer

You can reproduce the problem with :

final Document document = new Document("test", new BsonBinary("test".getBytes()));
final String json = document.toJson();
System.out.println(json);
JSON.parse(json);

and you got :
{ "test" :

{ "$binary" : "dGVzdA==", "$type" : "0" }

}

java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
at com.mongodb.util.JSONCallback.objectDone(JSONCallback.java:127)
at com.mongodb.util.JSONParser.parseObject(JSON.java:274)
at com.mongodb.util.JSONParser.parse(JSON.java:227)
at com.mongodb.util.JSONParser.parseObject(JSON.java:263)
at com.mongodb.util.JSONParser.parse(JSON.java:227)
at com.mongodb.util.JSONParser.parse(JSON.java:155)
at com.mongodb.util.JSON.parse(JSON.java:92)
at com.mongodb.util.JSON.parse(JSON.java:73)

($type, as I understand, must be an Integer but Extended JSon ask for a String)



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

Author:

{u'username': u'tomdcsmith', u'name': u'tomdcsmith', u'email': u'tomdcsmith@users.noreply.github.com'}

Message: Fix for JSONCallback to fully support extended binary

Added support for hexadecimal string values for the `$type` field in binary data.

JAVA-1796
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/600a37703ed6b4ad41bfab969a8efcbd51a00c6e

Comment by Jeffrey Yemin [ 28/Nov/16 ]

Pull request: https://github.com/mongodb/mongo-java-driver/pull/380

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