[JAVA-4023] Dates before epoch get serialized differently from dates after epoch Created: 25/Feb/21 Updated: 22/Jun/22 |
|
| Status: | Blocked |
| Project: | Java Driver |
| Component/s: | BSON |
| Affects Version/s: | 4.2.0, 4.2.1 |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Aalbert Torsius | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 1 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Windows, Linux (Docker) |
||
| Issue Links: |
|
||||||||
| Description |
|
When calling toJson() on a Document containing dates before and after epoch (1970), the result differs. Dates after epoch are represented as a string with an ISO 8601 formatted date, while dates before epoch are represented as the number of milliseconds to epoch. Expectation is that all dates get represented the same way. Minimal example:
|
| Comments |
| Comment by Jeffrey Yemin [ 26/Feb/21 ] | |||||||||
|
I linked this issue to a new issue in the drivers project: DRIVERS-1586. I'm going to change the status of this issue to Waiting on that one. Thanks for bringing this to our attention. | |||||||||
| Comment by Aalbert Torsius [ 26/Feb/21 ] | |||||||||
|
Well, that has to be the most unexpected expected behaviour I've come across in a long time. Yes, please do move it to the appropriate project and thank you for the workaround. I ended up using a fallback, but this looks cleaner. | |||||||||
| Comment by Jeffrey Yemin [ 25/Feb/21 ] | |||||||||
|
Yes, that's the expected behavior, as specified for all MongoDB drivers at https://github.com/mongodb/specifications/blob/master/source/extended-json.rst. If you'd like to propose a change to the specification, I can move/copy this issue to the DRIVERS project where we discuss requests such as this. I can offer as well the following workaround, which makes use of the Java driver's extensible Converter framework for writing JSON:
| |||||||||
| Comment by Aalbert Torsius [ 25/Feb/21 ] | |||||||||
|
In short, while using JsonMode.RELAXED (the default), JsonMode.EXTENDED is used for dates before epoch. |