[JAVA-488] Support serialization to Mongo extended JSON format Created: 13/Dec/11  Updated: 18/Jun/12  Resolved: 20/Apr/12

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

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


 Description   

Provide full support for serialization to http://www.mongodb.org/display/DOCS/Mongo+Extended+JSON. This can be useful for REST interfaces or other tools that use the java driver.

So as not to break existing applications that rely on the current behavior, the output of the com.mongodb.util.JSON.serialize method will not be changed. Instead, use the following:

com.mongodb.util.JSONSerializers.getStrict().serialize(...)



 Comments   
Comment by Jeffrey Yemin [ 18/Jun/12 ]

Closing for 2.8.0 release.

Comment by auto [ 04/Jun/12 ]

Author:

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

Message: JAVA-488: Rolling back unintentional API change
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/0da01d17c97b05e2ceae2556e86ca4cdce2cd5d7

Comment by auto [ 04/Jun/12 ]

Author:

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

Message: JAVA-488: API changes for JSON serialization. Clients should use static methods in the new JSONSerializers class
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/7d56b141c52b7aaed988abd26dc13b0f84c3925f

Comment by Jeffrey Yemin [ 20/Apr/12 ]

There will be a legacy serializer which works as the current driver does, so as not to break existing applications that rely on the current behavior. As Bryan says, the strict serializer will work as per the spec.

Comment by Antoine Girbal [ 20/Apr/12 ]

note that the java serialization may not respect part of the spec..
For example dates are output as string representing the date, not milliseconds (which is much better for human eye)

Comment by Scott Hernandez (Inactive) [ 20/Apr/12 ]

Yep, here is the actual commit: https://github.com/mongodb/mongo-java-driver/commit/5db92cb8bd04858eb36d9b81510f40b9188c3bb2

That was more for Antoine as a reference; sorry if that wasn't clear.

Comment by Jeffrey Yemin [ 20/Apr/12 ]

It does.

Comment by Scott Hernandez (Inactive) [ 20/Apr/12 ]

The implementation should follow this format, which is our standard: http://www.mongodb.org/display/DOCS/Mongo+Extended+JSON

Comment by Antoine Girbal [ 20/Apr/12 ]

what was the implementation like?
Sorry I wasnt very explicit when creating ticket, I think the idea is to make binary data properly roundtripable through JSON.
This can be done easily using a subobject like we do for other types.
So instead of

{a: <binary>}

Something like {a: {$bin: "base64str", $type: N}}

Comment by Bryan Reinero [ 20/Apr/12 ]

github commit 5db92cb8bd04858eb36d9b81510f40b9188c3bb2

Comment by Jeffrey Yemin [ 11/Mar/12 ]

This shouldn't be the default, since it changes current behavior, and is also not possible to distinguish the base 64 from other text. How about a method like JSON.serialize(Object o, JSON.Options options) where the Options class allows control over binary data presentation.

I don't see an obvious way to allow round-tripping with JSON.parse(String s)

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