[JAVA-2454] Document.toJson incorrectly serializes Date Created: 28/Feb/17  Updated: 28/Feb/17  Resolved: 28/Feb/17

Status: Closed
Project: Java Driver
Component/s: Documentation, JSON
Affects Version/s: 3.0.4, 3.2.2, 3.4.2
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: gross Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

linux 4.9.9, openjdk 8u121, mongodb 3.4.1, mongodb-driver 3.4.2/3.2.2/3.0.4


Issue Links:
Duplicate
duplicates JAVA-2447 Implement Extended JSON specification Closed

 Description   

new Document("a", new Date(1483228800000L)).toJson() // same with JsonMode.STRICT

produces

{ "a" : { "$date" : 1483228800000 } }

but

{ "a" : { "$date" : "2017-01-01T00:00:00.000Z" } }

or something similar expected.

Date is serialized to format which differs with described in docs and used by mongoexport tools.

If such behavior is expected and desired, than it should be at least mentioned in docs. It seems to be consistent through all 3.x drivers. Though mongoimport works fine with format produced by Document.toJson with current tools.



 Comments   
Comment by Ross Lawley [ 28/Feb/17 ]

Hi grossws,

Many thanks for the ticket, as you've already noticed there is some inconsistency between different MongoDB versions, tools and the outputted extended Json. All tools should be able to consume the older Json data formats but they may generate newer formats.

Its because of this the drivers team has been working on examining and specifying the extended Json format. Please see JAVA-2447, for the specification information and that ticket will cover this work.

All the best,

Ross

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