-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deserialization of timestamps with UTC timezone to LocalDateTime doesn't yield correct time #94
Comments
This makes sense, and as a further confirmation that this is should be the expected behavior, if you call
Though how to implement change, since would be a breaking change? There is the
One thing that isn't clear is whether Oracle's idea of default time-zone is the same as Jackson's context time zone (above). If it is, the existing feature could be used and implemented for |
Jackson does not use the local timezone as default for anything, anywhere, so I do not like the idea of starting to do that in some cases at this point. But even more fundamental problem I think is this: "local" values are not bound to ANY timezone: they are abstract. They should not get parsed to anything with timezone; and ideally I actually think that parsing should just FAIL if timezone information is encountered. If timezone information is to be used, proper type -- "zoned" date/time -- needs to be used. LocalXxx just will not do. But for "lenient" handling (which is currently the default), I suppose I could see either parsing into ZonedDateTime, then only using date/time part... or. Just dropping the timezone. I actually am not sure if former serves user better -- since |
Ah, good point. This strikes me as the cleanest and simplest of solutions here. . |
Exactly. Treating zone-less and zone-full dates the same is just wrong. I looked up the history. FasterXML/jackson-datatype-jsr310#68 introduced the change, copying code from FasterXML/jackson-datatype-jsr310#56. Rationale behind the change:
But the change did it wrong. JavaScript's My opinion is, it shouldn't even happen for "lenient" handling, because it is simply wrong. |
I took a look at that change (68) and it looks like that scenario you mention was never tested (only happy path) so thank you for the points, this will definitely have to be reviewed. |
It'd be great to get a fix in for 2.12 -- has to be minor release for behavioral change in most cases, at least if there is a reasonable chance that someone somewhere is counting on current behavior (even if objectively wrong one). |
We now have a PR (yay!) -- so do we still think this is a good idea, without need to configure anything? I just want to double-check if anyone (@kupci ?) has further concerns. |
@cowtowncoder Given your point, and also @ewirch 's, I think this is the right way to go. |
Ok, so... I changed my mind. :) So: code WILL allow "local-time plus 'Z' at the end" if (and only if!) "lenient" mode is enabled. This to still solve #68 case. I think this makes sense all in all, and will go in 2.12.0. Thanks to everyone who participated in discussion! |
Hello,
I'm using LocalDateTime to represent my timestamps on server side, but would like to transmit data in instant-like format in and out of my API, using the Z timezone. One of the advantages of doing this is that all clients treat the string as referring to the same instance, e.g. "new Date(string)" will result in same interpretation in all browsers, and built-in function such as date.toISOString() exists for formatting the string into an instant in time.
I ran into this behavior in Jackson during deserializing:
jackson-modules-java8/datetime/src/main/java/com/fasterxml/jackson/datatype/jsr310/deser/LocalDateTimeDeserializer.java
Line 75 in 66dce02
The behavior of this line is equivalent to just removing the Z character at end of timestamp and treating the rest as LocalDateTime, e.g. it will return the LocalDateTime in the UTC timezone. Wouldn't it make a lot more sense to convert UTC timestamp to LocalDateTime using system's own timezone, i.e.
so that the time as written by JavaScript would be understood as the same time after Jackson is processing it? I don't think a lot of people expect that a LocalDateTime should be interpreted to be in UTC timezone. For most of us, it's expected to be exactly what it says on the class name: a date and time in the local timezone.
The text was updated successfully, but these errors were encountered: