-
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
Support use of "pattern" (ChronoUnit
) for DurationSerializer
too
#189
Comments
Also note that above logic should only be invoked when configured to output "as timestamp" (as number) -- "as string" uses |
Hey guys, can I take this one too? |
@obarcelonap sure! I made some changes to the first one so make sure sync (some renaming). Was thinking that helper class probably should go under new |
Hey guys just worked a bit today on this
Branch here in case you want to take a look https://github.com/FasterXML/jackson-modules-java8/compare/master...obarcelonap:support-pattern-for-duration-serializer?expand=1 |
One comment on code below:
So is the idea to allow someone to provide their own
I'd incline to 'leave that as an exercise to the customer', i.e. the
and
There is access to
|
I think that constructor is probably called from |
exactly, I need to reduce the visibility of the constructor |
The thing about using But in any case, if I am not mistaken, current serialization of duration is as follows:
And I would adapt the code to consider
Would that make sense to you? |
In general this sounds good, but one question I have about case where both
Table above suggests that existence of "pattern" would sort of override shape being indicated as numeric (timestamp-y). I do agree that global I will try to follow up changes with lower delay this week so we can maybe get PR for this soon -- hoping now to get 2.12.0-rc2 over upcoming weekend, getting close to closing most things I really want for RC. |
Thanks for the feedback 🙆♂️ 🙆♂️
It made more sense to me when both are set, my reason behind is pattern is more specific since it changes the scale of the value, not only the precision (fractions). Since you're familiarized with the experience using the lib, I will go for your suggestion. Also, I reduced the scope a bit, getting rid of unit conversion with fractions since there is no direct support on it in
For the moment I will create the PR without unit fractions so we can get this merged and later on we can iterate if fractions are needed. |
@obarcelonap Sounds like a plan, yes. Getting non-fractional handling in quickly makes sense. |
Merged. |
(see #184 for background)
So, we should support use of
@JsonFormat(pattern = "HOURS")
(and "config override" equivalent) for writing too. As discussed on #184, there is gnarly challenge with backwards-compatibility -- change should only affect explicit pattern-using case.Another challenge is the possibility of fractional values: given
Duration
may not be exactly divisible by desired unit: for example, we might have "90 seconds" as value, but configured to use "minutes", resulting in1.5
(ideally).If it is possible to calculate this accurately (enough), I'd like to do that, but I am not sure it is.
If not, I suggest that only one specific case of fractions would be supported: that of "SECONDS" as explicit unit. It would be output as fractions as needed, based on underlying seconds/nanoseconds values.
The text was updated successfully, but these errors were encountered: