[JAVA-1354] JSON date parsing fails with timezones other than Z Created: 07/Aug/14 Updated: 14/Mar/17 Resolved: 14/Mar/17 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | JSON |
| Affects Version/s: | 2.12.3 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | Frej Bjon | Assignee: | Jeffrey Yemin |
| Resolution: | Won't Fix | Votes: | 1 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Windows |
||
| Issue Links: |
|
||||||||||||||||
| Backwards Compatibility: | Fully Compatible | ||||||||||||||||
| Description |
|
When the parser encounters a field with e.g. { "$date" : "2013-12-03T10:41:22.393+0200" }the resulting value is null. The reason is that the format string given to SimpleDateFormat is "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" which requires a literal 'Z' rather than actually parsing the timezone. Changing the string to "yyyy-MM-dd'T'HH:mm:ss.SSSX" should work better. |
| Comments |
| Comment by Jeffrey Yemin [ 09/Mar/17 ] | ||||||||
|
adamwasila, I investigated a bit more and found that as of MongoDB 3.0 mongoexport outputs dates in Zulu time:
Furthermore, MongoDB 2.6 will be EOLed this fall. Given that, I'm not convinced that this issue should be addressed. | ||||||||
| Comment by Adam Wasila [ 21/Jan/17 ] | ||||||||
|
Ok, nailed it - I pushed pull request for this one. It has fallback code to work on 1.6 too and also some tests to cover this code branch when compiled in regular java8. I made some performance tests and fallback code (so only if java 1.6 is used) seems to be 3x slower than regular one (1.7+). This is because of exception catch and all that code that happens later. It isn't that big deal I think, especially that old code would return null anyway, thus making timezoned dates useless. | ||||||||
| Comment by Jeffrey Yemin [ 21/Jan/17 ] | ||||||||
|
We compile on java 8 but it has to run on java 6 with no required dependencies. | ||||||||
| Comment by Adam Wasila [ 21/Jan/17 ] | ||||||||
|
I made some that simple fix and added it to the pull requests list. There is one side effect though - it will work only on java 7+ (but is that driver code compiling on 1.6 anyway?) | ||||||||
| Comment by Jeffrey Yemin [ 07/Aug/14 ] | ||||||||
|
Note that this is a change in MongoDB 2.6:
| ||||||||
| Comment by Jeffrey Yemin [ 07/Aug/14 ] | ||||||||
|
Thanks for the bug report. We will schedule this into an upcoming release. | ||||||||
| Comment by Frej Bjon [ 07/Aug/14 ] | ||||||||
|
I should also note that the JSON parser fails on mongoexport output, since mongoexport produces dates with the local timezone. |