-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
StdDateFormat: add option to serialize timezone offset with a colon #1744
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
Comments
I agree in that it'd be good to improve inter-operability here. Unfortunately this seems like a tricky thing to do. It is possible to specify format (via |
Maybe we could make
This way they have the full power of the StdDateFormat without having to subclass it and can customise its behaviour without requiring the introduction of new SerializationFeature. |
That sounds like a good idea to me. For Jackson 3.0 we can get more creative -- I think (De)SerializationFeature's could use breaking up. And perhaps there's room for introducing other properties for for (also: I think you mean "colon" for the character; I modified title) |
Nice. Let me prepare à PR for this. |
May be you should first review the other pending PR since they affect the same class. Otherwise we gonna have merge issues... |
Ok, went ahead, change setters -> with-mutator. Will be in 2.9.1. |
Hello, @cowtowncoder, just to confirm, there were no changes regarding the colon use on @jsonformat right? I couldn't get a working pattern that included it in the timezone. I also didn't manage to get StdDateFormat to work with ZonedDateTime. My solution right now is a custom serializer that inserts the colon manually. Is there a better way to do it in 2.9.1? Sorry for the noobish question, I'm new to the web world. |
@caeaugusto Use of custom formats that include colon should, however, work with newer types, via https://github.com/FasterXML/jackson-modules-java8/issues So basically we have somewhat distinct handling of different date/time types: old JDK date/time, new (java 8) JDK date/time, and Joda. |
@cowtowncoder, thanks for the explanation. Originally I was using @jsonformat with the pattern "yyyy-MM-dd'T'HH:mm:ssZ" for a ZonedDateTime and that serialized the timezone with no colon. That was not a problem until I tested against Safari so I had to change it. I understood that "yyyy-MM-dd'T'HH:mm:ssXXX" should serialize the timezone with the colon but the JSON produced has Z instead of the 4 numbers with the colon. I also understood that "yyyy-MM-dd'T'HH:mm:ssZZ" should serialize the timezone with the colon but that serializes it without the colon. I honestly don't know if that's a bug and if it's jackson's, or if I'm using the wrong patterns. If it is indeed a bug, I'd be happy to file it. PS: I do not use Joda at all. |
Have a look at FasterXML/jackson-modules-java8#38 |
@brenuart thanks for helping, although I'm a bit confused because I don't have much knowledge on the topic. cowtowncoder mentions changing constructors to protected but they already are, and it seems to me that you would need them public so you wouldn't need MyInstantDeserializers class, right? Even if this is right, I think that I should only need the JsonFormat annotation for my case. |
@caeaugusto Reference issue seems to be about deserialization so it may not directly help, although it is about same challenge wrt colons (or no colons). Fundamental challenge has to do, I think, about Java 8 date formatting strings and options; Jackson module does not do any composition by itself (unlike latest version of So I guess I would say that if JDK 8 date/time formatters can be configured to produce desired output, Jackson should allow such usage. If formatters are incapable of that for some reason it may be JDK issue. I think I have seen some allegations that latter might be true but I don't have first-hand experience or knowledge myself. |
@cowtowncoder it seems to me (not totally sure though) that the problem is indeed with the JDK. Thank you very much for taking your time to answer my questions! |
@caeaugusto no problem; and I am sorry to hear in a way it is JDK issue... since it is not something we can easily address at this point. But if you or anyone else finds workarounds, links to documentation, maybe even reported bugs in oracle's bug tracker, those would be good additions here. |
|
Jackson's StdDateFormat serializes datetimes without colon in the timezone offset, eg.
1970-01-01T01:00:00.123+0100
.Java8 and Joda have decided to include a colon in the offset, eg
1970-01-01T01:00:00.123+01:00
.Although Joda accepts to deserialize a datetime with or without the colon, Java8 considers the colon as mandatory and fails to deserialize datetimes produced Jackson's StdDateFormat.
In addition, some platforms like iOS also require a colon in the offset and are therefore also unable to read dates produces by Jackson's StdDateFormat.
Consequence: It would be nice if Jackson's StdDateFormat could be easily configured, extended or customized to include a colon in the timezone offset.
The text was updated successfully, but these errors were encountered: