[JAVA-4198] BasicDBObject.toString() returns STRICT extended JSON, expecting RELAXED Created: 16/Jun/21  Updated: 27/Oct/23  Resolved: 09/Jul/21

Status: Closed
Project: Java Driver
Component/s: BSON, JSON
Affects Version/s: 3.7.0, 3.12.0
Fix Version/s: None

Type: Task Priority: Unknown
Reporter: Adamo Tonete (Inactive) Assignee: Unassigned
Resolution: Works as Designed Votes: 0
Labels: internal-user
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to JAVA-2556 Change toJson method contract to defa... Closed
Case:

 Description   

Older versions (pre-3.7) of the driver when calling BasicDBObject.toString() returns simple JSON output, i.e

{
   "name" :  "foo", 
   "age" : 10}

New versions (3.7 to 3.12), when calling the BasicDBObject.toString() method returns STRICT extended json: i.e

{
   "name" :  "foo", 
   "age" : {"$numberLong": 10"}
}

Would it is possible to override the default behavior by some flag instead of using the BasicDBObject.toJson(JsonWriterSettings). Some applications rely on the prior behavior to feed other libraries that doesn't expect extended json.
 



 Comments   
Comment by Jeffrey Yemin [ 16/Jun/21 ]

Hi adamo.tonete

We can't really add any new behavior in the 3.12 driver, since at this point we're only doing patch releases according to the definitions in https://semver.org/.

Note though that in the 4.0 release of the driver, BasicDBObject.toString() does return RELAXED extended JSON.

Comment by Jeffrey Yemin [ 16/Jun/21 ]

A few notes:

  • In scope of JAVA-2521, the JSON output of toString changed from using the deprecated com.mongodb.util.JSON class to org.bson.JsonWriter, using STRICT mode. That change was included in the 3.7 release of the driver.
  • In scope of JAVA-2556, the JSON output mode was changed from STRICT to RELAXED. That change was included in the 4.0 release of the driver. It affects both the toString and toJson methods of BasicDBObject
  • The differences between STRICT and RELAXED are specified here.
  • Even in RELAXED mode, there are still subtle differences between the output created by com.mongodb.util.JSON and RELAXED extended JSON. The output of the former was never fully specified. As an example, binary data was output as the string "<Binary Data>"".
Generated at Thu Feb 08 09:01:28 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.