[JAVA-832] NumberLong is not properly round tripped by the JSON serializer / deserializer Created: 20/May/13  Updated: 04/Dec/13  Resolved: 04/Dec/13

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

Type: Improvement Priority: Major - P3
Reporter: Antoine Girbal Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-5424 Shell doesn't re-save retrieved integ... Backlog

 Description   

the JSON serializer (used in most outputs) writes Number / NumberInt / NumberLong as just a regular number.
The JSON deserializer tries to be smart and either uses a Number or a NumberInt based on how large it is.
The behavior should be equivalent to the shell or mongoexport / import.
At the minimum it should encode NumberLong as

{ $long: N }

so that it can be round tripped.



 Comments   
Comment by Antoine Girbal [ 04/Dec/13 ]

I have added a comment at SERVER-11136
If this was needed in other tools, would make sense to have it in the extended spec and drivers.

Comment by Jeffrey Yemin [ 04/Dec/13 ]

Please re-open if you have more information.

Comment by Jeffrey Yemin [ 21/May/13 ]

What have you tried that doesn't work? Much of the JSON serialization was re-implemented in the past year.

Comment by Antoine Girbal [ 21/May/13 ]

Overall the driver does not abide by the rules here:
http://docs.mongodb.org/manual/reference/mongodb-extended-json/
The Java driver's output was implemented at a time when both the shell and mongoexport where doing things without real logic (e.g. a date would be just a string).
The rules were defined later on...

Anyway I just looked at JSON.parse() code and it detects double vs int vs long, so at least data will not be lost there.
But it could switch long values to int if they are not large enough, I wonder if that could cause problems, that's why there is NumberLong in shell.

Comment by Jeffrey Yemin [ 20/May/13 ]

Furthermore, this is what mongoexport does:

new-host-5:~ jeff$ mongo --port 30000
MongoDB shell version: 2.4.1
connecting to: 127.0.0.1:30000/test
> db.test.insert({ l : NumberLong(4) })
> db.test.findOne()
{ "_id" : ObjectId("519a9edd4458022a12a02015"), "l" : NumberLong(4) }

new-host-5:~ jeff$ mongoexport --port 30000 -d test -c test
connected to: 127.0.0.1:30000
{ "_id" : { "$oid" : "519a9edd4458022a12a02015" }, "l" : 4 }

Comment by Jeffrey Yemin [ 20/May/13 ]

There is no $long syntax defined in http://docs.mongodb.org/manual/reference/mongodb-extended-json/.

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