[JAVA-2702] BasicDBObject.parse fails to parse json if it contains big numbers Created: 13/Dec/17 Updated: 27/Oct/23 Resolved: 14/Dec/17 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | JSON |
| Affects Version/s: | 3.4.3, 3.6.0 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | Mikhail Danilov | Assignee: | Ross Lawley |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
Input:
Expected behavior: Actual behavior:
|
| Comments |
| Comment by Jeffrey Yemin [ 14/Dec/17 ] | |
|
mdanilov thanks for the feedback and for working through this issue. For now, your best bet is to pre-process your JSON, as you would have to do with other MongoDB BSON types that have no native JSON representation (e.g. ObjectId, Date) | |
| Comment by Mikhail Danilov [ 14/Dec/17 ] | |
|
Jeff, thanks for explanation. | |
| Comment by Jeffrey Yemin [ 14/Dec/17 ] | |
|
JsonReader already supports Decimal128 but requires a specific escape syntax to specify values of that type, as specified in our Extended JSON specification. The JSON input has to look like this:
The rationale for distinguishing Decimal128 values from Double values is that they don't just differ in size, but in semantics. Decimal128 values can represent decimal values like 0.1 exactly, for example, while Double values can not. They can also represent trailing zeros losslessly, so, for example, 1.40 is distinct from 1.400. See the Wikipedia article for more details. | |
| Comment by Mikhail Danilov [ 14/Dec/17 ] | |
|
BasicDBObject#parse uses JsonReader under the hood. And JsonReader's javadoc says:
Also in driver documentation http://mongodb.github.io/mongo-java-driver/3.6/bson/extended-json/:
Based on that I guess that feature request for Decimal128 support in JsonReader/JsonScanner should be created. And this issue should be discarded since BasicDBObject#parse correctly handles json according to javadoc. Any thoughts on that? | |
| Comment by Mikhail Danilov [ 13/Dec/17 ] | |
|
Hello @ross.lawley, Thanks for quick response. I used BasicDBObject as a replacement for com.mongodb.util.JSON (is deprecated in 3.6) and extended-json was not mentioned in JSON's javadoc. Does driver offers any other tools to parse arbitrarary json string (non-extended) to BasicDBObject? | |
| Comment by Ross Lawley [ 13/Dec/17 ] | |
|
Hi mdanilov, Thanks for the ticket, this is currently expected behaviour as BasicDBObject#parse handles extended-json, as stated in the API documentation:
Ross |