-
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
DurationDeserializer
should use @JsonFormat.pattern
(and config override) to support configurable ChronoUnit
#184
Comments
Yes, |
@JsonFormat.pattern
on property
Marking as targeting 2.12 since probably needs refactoring of base serializers. |
Hey @cowtowncoder I am interested in this one. Can you guide me a bit through the required changes? Thanks in advance |
@obarcelonap first of all, that would be excellent! It might make sense to have a look at Joda module (https://github.com/FasterXML/jackson-datatype-joda/) and compare deserializer implementations. But the basic idea is that annotation information is available in If you want to try working on this, use |
Additionally, I noticed a suspicious looking piece of code related to the DurationDeserializer configuration : Lines 134 to 139 in 37f55ed
The Feature is about deserializing to nanos, but it deserializes as seconds. Do you want me to make a separate issue for this or solve it as part of this one? Was already like this in 2.10.2 |
@cowtowncoder did some prototyping today, could you check how it looks like? If that's ok I will test it. thanks!! |
Should be a separate bug, with test case and so on. But I think that is the correct behavior, see #165, sometimes the flags are a little ambiguous. |
Looks good so far, only thought is for the above enum, the patterns ("d", "h", ...) should be available somewhere already, in the Jackson core, and then you can map DurationPattern to that? |
I am not experienced with jackson-core but I can't find anything similar. Other option is just rely on Duration::of method (instead of specific methods) so the enum is not needed as the received format could be parsed as ChronoUnit. |
I am trying to unit test the class and I am having compilation issues when executing any test through intellij. Compilation error is related to missing jackson dependencies like jackson-core. But it works if I run tests trough mvn. Any clue? Do I need to do something special when importing the mvn project in intellij? |
I haven't seen that but taking a look, it does seem others are running into this problem, so you might find some solutions below:
|
I managed to run the test after deleting some files in idea config dir :? Now the issue is about the testing. After adding my tests in DurationDeserTest some of the other ones are failing. Is like my tests are polluting somehow the whole test suite because if I comment them everything is on green. I think after solving this, code is ready. Let me know if I am missing something. |
Not sure if this is the root cause but I know that some test classes incorrectly modify shared datetime/src/test/java/com/fasterxml/jackson/datatype/jsr310/deser/DurationDeserTest.java it does not have this problem. |
@obarcelonap Did not see anything that would explain test fails, although one change seemed bit odd:
as if it was missing |
…(long,TemporalUnit). ref FasterXML#184
@cowtowncoder that was the thing, missing to reset the value to null. Created the PR :) |
…ion::of(long,TemporalUnit). ref FasterXML#184
…n Duration::of(long,TemporalUnit). ref FasterXML#184
…based on Duration::of(long,TemporalUnit). ref FasterXML#184
…alizer based on Duration::of(long,TemporalUnit). ref FasterXML#184
… deserializer based on Duration::of(long,TemporalUnit). ref FasterXML#184
…(long,TemporalUnit). ref FasterXML#184
@obarcelonap Thanks! I think this is getting ready. One thing I'll need is CLA, from: https://github.com/FasterXML/jackson/blob/master/contributor-agreement.pdf and usually the easiest way is to print, fill & sign, scan/photo, email to Thank you once again for the PR! |
Just sent the CLA by email. |
@obarcelonap thank you again for contributing this, taking your time. Thank you @kupci for comments, pointing out issues. First, a bigger thing to discuss: Seconds vs Milli-seconds defaulting (Very Broken Behavior). It took me a while to get the context again, and I finally realized what was pointed out earlier: existing handling is pretty much broken wrt unit handling, assuming:
Regarding this, I don't think we can change defaults, even if they are wrong. Systems that use Jackson have had to rely on these defaults, work around them. If we change semantics we will break systems. Regarding this particular issue, I propose that we only change time-unit when user explicitly uses We COULD additional specify a configuration setting for the module to allow fixing this issue: something like "setDefaultToSecondsForDuration()" in This problem also concerns |
After explaining how I see the biggest problem, here are more targeted notes about this specific PR.
I think above changes are quite close to PR but I wanted to reach consensus now. |
Agree, though one question on "same logic", you mean the original (pre-PR) logic right? One addition to this is that, playing around a bit with the |
@kupci Yes, true. There does not seem to be a way to really support fractions for anything but So for 2.12, it does sound like we should start by supporting only But then again, I am beginning to wonder whether we have time to do proper job here for 2.12 or not. I'd rather not make changes unless they clearly improve handling. |
Hey guys, thank you for all your comments, I try to disconnect in the weekends and have good quality family time and now checking the email I see all this interesting discussion, amazing job. If I am not wrong, I'd need to fulfill the following requirements:
Mainly @cowtowncoder 's notes adapting slightly the last point to do not support floating point numbers.
Is there any planned schedule for releasing 2.12 version? I do think changes are really narrowed in a class and if there is an agreement in the bullet list above I can make that happen :)
IMO this change will provide better Duration handling will avoid the accidental complexity added by the library just because it only supports seconds units gracefully. If there are so many questions left, maybe retargetting to 3.0 makes sense, I can try to take a look on how it would this changes in that version. Let me know your thoughts before adapting the code with the latest comments in the current PR. |
@obarcelonap Ah, just to clarify: if not 2.12, I'd target 2.13, not 3.0 -- 3.0 is still too far out (or undefined). So, on timing, probably we can get this in 2.12 still. I think we'll iterate over this.
with secondary constraints;
That seems doable to me. Looking forward to modified version! |
…(long,TemporalUnit). ref FasterXML#184
Pushed latest changes, please let me know your feedback. |
…(long,TemporalUnit). ref FasterXML#184
@JsonFormat.pattern
on propertyDurationDeserializer
should use @JsonFormat.pattern
(and config override) to support configurable ChronoUnit
Merged, will be in 2.12.0-rc2 |
When deserializing
DurationDeserializer
treats all durations of number values as seconds and delegates string values toDuration.parse
.Versions
Example
The Exception thrown by the second
readValue
call:Even though
JsonFormat
doesn't explicitly mention anyjsr310
classes in its documentation they should still work with it. Especially sinceDurationDeserializer
already respectsJsonFormat#lenient
.The text was updated successfully, but these errors were encountered: