-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Behaviour of custom date format with regards to the ObjectMapper's default time zone #1661
Comments
Hmm. I may be wrong, but I think the fundamental question is this: when given a Does this make more sense? I remember struggling with this, in trying to figure out how various pieces of information should be combined. That said, due to complexity of logic it is possible that something may be handled in demonstrably wrong way. |
I think the general rule stated above is correct and must be applied consistently everywhere. This means the TimeZone of the custom DateFormat must be ignored and always forced to whatever This will make the behaviour and the API more consistent and understandable. There will be one single place where the default TZ must be configured: the ObjectMapper. Furthermore, knowing that Jackson's default TZ is UTC, it is hard to explain someone he will get a different behaviour if he explicitly sets the TZ to UTC himself on the mapper... (that should have no effect). |
In summary, the custom DateFormat always has its TimeZone forced to whatever `Settings.getTimeZone()` will return. Provide an additional fix in `withTimeZone` to handle the case where `_dateFormat` is null (since this is allowed by `withDateFormat`). Update test case to reflect the fixed behavior.
No: if user feels compelled to specify It is possible documentation should be clarified, but at this point further changes seem more likely to confuse things, and lead to more bug reports. |
I'm not sure if this is the same issue: Until 2.9: Since 2.9: |
The fix proposed in this issue has not been merged (yet). On the other hand, it would affect only those using a custom date format instead of Jackson's StdDateFormat. I think your issue is similar to #1657 |
@Martin-Wegner it definitely sounds like #1657, which may have made it in 2.9.0.pr4 (not 100% sure, fix is quite close to release time), but is definitely in |
Not sure if and how to proceed here; closing for now. |
Tested with Jackson
2.8.8
and2.8.9
.The general rule with the StdDateFormat with regards to the TimeZone is:
This rule remains valid when the
@JsonFormat
annotation is used on a property unless it forces an explicit timezeone, in which case it takes precedence.One would expect the same behavior when the StdDateFormat is replaced by a custom DateFormat on the ObjectMapper. In other words, the timezone of the DateFormat should be of no importance since the ObjectMapper's default is used whenever needed.
However it appears this behaviour is not always respected and depends on whether the mapper has been explicitly configured with a TimeZone or not.
Suppose the following custom date format:
Use it on a vanilla ObjectMapper without any further configuration:
This produces a date with
GMT+4
although we would expect UTC according to the "rules" described above.Do a second test and use the same date format on an ObjectMapper whose timezone is explicitly set to UTC. Since UTC is the default, this test should behave as the first...
Now this produces a date in
UTC
and notGMT+4
anymore.. This is compliant with the rules, but unexpected in the light of the first test.Do the test once more with
GMT+2
instead goUTC
and the date will be inGMT+2
...This case is covered by the
DateDeserializationTest#testDateUtil_customDateFormat_withoutTZ()
test case submitted in PR #1660.Could this be related to https://github.com/FasterXML/jackson-databind/blob/2.8/src/main/java/com/fasterxml/jackson/databind/cfg/BaseSettings.java#L245-L249 ?
The text was updated successfully, but these errors were encountered: