-
Notifications
You must be signed in to change notification settings - Fork 82
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
DateTime can't be serialized with its own zone (WRITE_DATES_WITH_CONTEXT_TIME_ZONE not respected) #146
Comments
Additional information: My use case is implementing a JSON API that needs to return date-times with (potentially) different time zones. Since I can't have a fixed time zone, the existing behaviour prevents me from using Also, I'm aware that the documentation of |
Wrt Whoever has time & itch to look into this may find other blockers, but that will be found by trying to make it work. I don't have time to work on this any time soon, but I make time to help others who do. Fwtw. |
Is java.time a better bet these days? That is, does https://github.com/FasterXML/jackson-modules-java8 Java 8 Date/time support time zones? |
Java 8 date/time module has supported both time offsets and time zones from the beginning so it should indeed be better bet. |
@pvgoran Reading through Javadoc And if so, this could be done without introducing new Joda-specific features or changing compatibility (well, theoretically there would be change of course, making some feature's alternate setting have an effect -- if someone was using both Joda and Java 8 date/time, setting this feature to affect latter -- but seems bit remote) |
Added reproduction (failing test) as Also tried a quick fix to
but that didn't work (I think But perhaps someone else could try to figure it out? |
Well, java.time is generally considered to be better. However, it does lack some features and convenience of Joda Time. Besides, not everyone has a freedom to choose. :) |
Yes, I think so.
Great! Adding proper tests would be a major obstacle for me in trying to implement this. :)
Could you share what exactly you tried that did not work? |
I'd have to go back to code later on, but as per my note, method
change line
to avoid setting Test I added is |
(This issue is about the same problem as #92. However, I decided to create it because the old issue describes the problem in an indirect way, and because
WRITE_DATES_WITH_CONTEXT_TIME_ZONE
was added to https://github.com/FasterXML/jackson-databind since then.)In version 2.18.1,
DateTime
instances are always serialized usingObjectMapper
's time zone (even if it was not explicitly specified -UTC
is used in this case), rather than withDateTime
's own zone. Disabling theWRITE_DATES_WITH_CONTEXT_TIME_ZONE
serialization feature (which was added for FasterXML/jackson-modules-java8#222 to address the same problem but with JSR-310 date-time types) does not help.Test code:
Output:
Expected:
The text was updated successfully, but these errors were encountered: