[JAVA-3268] Bson JsonReader failed to parse the date time string "2011-01-14T00:00:00.000-0800" Created: 16/Apr/19 Updated: 06/May/19 Resolved: 02/May/19 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | BSON |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | jin | Assignee: | Jeffrey Yemin |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Description |
|
Using BSON JsonReader to parse below JSON string got JsonParseException with error message "Failed to parse string as a date", but this JSON string can be imported successfully using mongoimport. It looks like JsonReader using java8 java.time.format.DataFormatter.ISO_OFFSET_DATE_TIME to parse java string, is it possible to extend the the pattern to be more flexible?
|
| Comments |
| Comment by jin [ 02/May/19 ] | ||||||
|
OK, thanks for the detailed explanation! | ||||||
| Comment by Jeffrey Yemin [ 01/May/19 ] | ||||||
|
Hi zhao Sorry for the confusion here. The drivers extended JSON specification is what all of our drivers have standardized on as of May 1, 2017. My apologies that https://docs.mongodb.com/manual/reference/mongodb-extended-json/#date is not consistent with the specification. The specification states that the "relaxed" form of a BSON date is:
RFC-3339 gives the rules for the time offset as:
The driver uses java.time.format.DateTimeFormatter#ISO_OFFSET_DATE_TIME to parse date strings, so the driver is in line with both our own specification and standard support in the JDK itself. I am not eager to introduce more incompatibilities between our supported drivers by adding the ability to parse this string in the Java driver, so I'm inclined to close as Won't Fix and file a ticket to update https://docs.mongodb.com/manual/reference/mongodb-extended-json/#date | ||||||
| Comment by jin [ 29/Apr/19 ] | ||||||
|
Hi Jeff, In https://docs.mongodb.com/manual/reference/mongodb-extended-json/#date, the date string in strict mode is ISO-8601 date format with a mandatory time zone field as the template YYYY-MM-DDTHH:mm:ss.mmm<+/-Offset>. And in ISO_8601 wiki, the time offset format can be any of below formats:
So I think "{{±hhmm" is valid format for date time string in strict JSON. In additional, the above string can be imported with mongoimport, the date string can be parsed correctly:
so I feel like BSON java driver may need enhance to support this format as well. What do you think? Jin
| ||||||
| Comment by Jeffrey Yemin [ 24/Apr/19 ] | ||||||
|
Is there a standard (RFC or ISO) that defines the format that you're using? RFC 3339/ISO 8601 is a bit different, and requires something like 2009-04-01T00:11:00-08:00. This is what the driver currently supports, and I'm not inclined to change it unless it conforms to a widely implemented specification. |