-
Notifications
You must be signed in to change notification settings - Fork 66
PR to resolve #13 - ISO 8601 serialization of types ZonedDateTime and OffsetDateTime #15
Conversation
…AS_TIMESTAMPS is disabled
@zkiss Thanks! I'll have to get a second opinion from Nick, just to make sure; sounds legit to me. @beamerblvd What do you think? |
No worries! On a sidenote, |
Released using maven. Maybe master has issues due to changes in 2.5.0-SNAPSHOT for databind? |
I have just noticed that Since the issue is about that the library does not produce ISO compatible date strings, I have changed the I am a bit unsure about this change though, as it leads to loss of data - the time zone information. And also to failing tests. I am afraid it might be impossible to convert ZonedDateTime in a strictly ISO string, which is probably why the formatter My question is what would be the preferred approach here - is the aim of this module to produce ISO compatible date strings or to keep the data and break ISO compatibility? Personally I would go for ISO serialization and rely on This PR cannot be merged in the current state. |
I have chosen to go for ISO compliant serialization and change the expectations in the tests. In cases where a location specific timezone was expected in the deserialized object, the initial conditions were changed to use fixed offset based This PR now can be merged and contains what I think most people would consider an acceptable ISO compliant behaviour. |
@cowtowncoder, @beamerblvd, just pinging you guys to have a look, maybe you've missed it. |
I haven't done anything on this, but in absence of concerns, I could merge it for inclusion in 2.6, now that 2.5 is safely out. |
I'll take a look at this tonight and provide feedback. Nick Sent from my iPhone, so please forgive brief replies and frequent typos
|
Did you take a look at it? :) |
There was some discussion regarding this PR in the issue: https://github.com/FasterXML/jackson-datatype-jsr310/issues/13 We need to make a decision if we still want to merge this PR. A solution to the issue is desired though, and I am also willing to deliver that, however a decision is needed on how to proceed. |
Apologies for my silence here, but I really do not have enough expertise here to have specific opinion. What I think is needed is to figure out who should own this module, and decide. @beamerblvd wrote this module and would be the best candidate, but I think he has been busy lately. |
I see two course of actions regarding the code:
Both ways will then require further dev work in this module and the joda module to handle the feature properly. Merging this PR results in ISO compliant date strings but introduces loss of data and potentially a false sense of safety when people are dealing with |
@zkiss quick question: have I already asked for a CLA? (https://github.com/FasterXML/jackson/blob/master/contributor-agreement.pdf) Given that there has been very little feedback, I think I would go ahead and let you choose the path, with just one limitation: I think that the default value for new feature should be such that it does not break existing code. This means that ISO-8601 compatibility forcing should not be the default. An additional suggestion I have, for path forward, would be to actually add code in Joda (etc) to detect additional timezone information, and simply discard it if it can not be handled. While I support strict handling in most cases, here it seems better to be bit more liberal with what you accept, because date/time handling is already a huge hassle. Adding more strictness seems counter-productive. So:
Does this make sense? |
Forgot to mention: CLA should be printed, filled-in & signed and then emailed to |
@@ -66,7 +77,7 @@ public void serialize(T instant, JsonGenerator generator, SerializerProvider pro | |||
} | |||
else | |||
{ | |||
generator.writeString(instant.toString()); | |||
generator.writeString(this.toIsoString.apply(instant)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please disregard this. I misunderstood in which file this change was taking place.
I don't understand why this change is necessary. According to the API documentation, Instant#toString
already outputs a strictly ISO-compliant string.
Given addressing of my comments, this looks good to me. But I want to better understand how this is supposed to address adding zone information—looks like that's missing. |
Thanks everyone for the feedback. Closing the PR because this would be a non-backwards compatible change - based on our discussion this should not be merged. Will implement the |
@cowtowncoder, @beamerblvd Regarding the way forward: I fully understand and agree in general with the principle of introducing changes in a backwards compatible manner. However after giving it some thought, in my opinion it is impossible in this case to be backwards compatible. This is because the currently released joda module and jsr310 module have exactly the opposite behaviours. Joda module currently does not preserve time zone information - it works the same way this module would with this PR merged. My guess is that joda module is used much more widely than this one. For this reason I believe that the default value of the 'time zone preserving' config switch should be to not preserve the time zone information and produce iso8601 compliant strings. If we agree in this, then my suggestion would be merging this PR and then adding the switch afterwards. If we don't agree, then the introduction of the new It is also a possibility that the joda module would ignore the new Regarding the name of the |
Ok. Yes, I see the conundrum here. I also agree in that changing behavior of Joda module in backwards incompatible way would not be well received. |
I concur with comments so far: I do not like backwards-incompatibility, and if a choice is needed, I would rather upgrade this module first, to allow transition, and postpone decision on Joda (if need be) until 2.7. But as one minor starting point, since suggestion to add FasterXML/jackson-databind#794 and can easily add it. From discussions, it seems we could choose default either way; however, it sounds like preferred value would be At this point it may be relevant to check out usage. From Maven Central, actual download counts for top 3 datatype modules are as follows:
so while Joda is the top dog, JSR-310 module is perhaps surprisingly almost 50% as popular, by mere download counts. This does not necessarily mean similar range of usage, as some frameworks may default to including many modules (Spring Boot and DropWizard may both include both, for example). |
Sounds like we need to provide backwards compatibility options then. My preferred solution for that would be writing a new serializer
Is this acceptable to everyone? |
@zkiss Unfortunately I am not sure that is any better than other options -- many users simply upgrade versions of modules with no other changes, and expect things to work. To me there are 2 main goals:
The non-goal, then, would be "switch by default to new ISO-8601-compliant behavior", because I do not see a way to achieve that with (2). But to simply achieve (1) and (2), how about following steps instead I. Add new constructor, This way default behavior is the old one (for drop-in-place upgrade), but users can easily switch to new, better default. While not perfect, this seems to me a possible way forward. And at this point I would rather take that, than to wait for the perfect answer. |
And one more. There is also one variant of the idea above: instead of adding new constructor, we could instead create a new module class, so that:
we could easily refactor things so that most code would be shared. This might actually be the better way to do this, mostly because creating instances using no-args constructors is bit easier with some frameworks. Plus we wouldn't need to consider whether to change no-args constructor of the existing module: we would instead deprecate and (eventually) remove that module class. |
I think I like the new module idea. How about |
OK, let's go with the new module idea! I'd mark |
Ignore earlier version of this comment. Page didn't load some comments so I missed half the conversation. With a new module what will happen with the |
+1 for new Module, deprecating the old Module. This makes things very clear to framework users. |
@wselwood findAndRegisterModules() is an interesting part. If I remember correctly, it uses this file:
and we thereby control what is visible. However, our choice is pretty much just including one, both or none there. This is why I personally never use auto-detection; it tends to lead to accidental inclusion of things due to things getting added to classpath, often accidentally via transitive dependencies. So the question here would be whether to include old or new module in classpath (I don't think "both" makes sense). The nuclear option would be to create a new project. But that does seem... bit extreme. |
As to name: I like both |
By the sounds of it the best we can do in that case is optimize the point of breaking @cowtowncoder My vote would go to JavaTimeModule but I am pretty happy with either name. |
@wselwood Agreed. Either name is fine -- what is needed would be updates to PR, to allow both options. And one more note on auto-registration, this: FasterXML/jackson-jaxrs-providers#39 is a fix to JAX-RS provider, which now provides two sets of jars: one with auto-registration metadata; other without one. Maven classifier is used to specify one without metadata, to retain backwards-compatibility. |
@zkiss Do you think more information is needed here? Can I help in getting this implemented, as discussed? I am hoping to get this in 2.6 (ideally, 0-rc2). |
@cowtowncoder and all, thanks for all the input. I have pushed a new module class The module is not autodetected by default. If there are any changes needed, please let me know! |
@zkiss I trust that changes are good, but just in case others have comments, I'll wait until merging this. Hoping to merge tonight or tomorrow. |
One thing I forgot to mention: because of the duplication of all the tests (thinking in the short term here), this should either be merged real soon (before merging anything else with test changes) or a new way of testing the old and new behaviour should be implemented in this PR. |
I'll postpone other merges, if any (none pending). Thank you for noting this problem. I am fine with duplication on short term. |
@cowtowncoder I think the old module
|
@zkiss I can deal with that one. Module sets up somewhat strict limits so that no warnings are allowed -- bit extreme, and perhaps could be reconsidered. But for now, I can just fix that, after merge. |
PR to resolve #13 - ISO 8601 serialization of types ZonedDateTime and OffsetDateTime
As this has been discussed quite much I think many of us are interested in a release. Any possibility to do it in the near future? |
This will be included in 2.6.0-rc2, once I resolve couple of issues from |
A solution proposal for issue #13.