Create JsonDuration from java.time.Duration#17
Merged
runeflobakk merged 4 commits intomainfrom Mar 17, 2026
Merged
Conversation
To e.g. enable initializing JsonDuration fields from existing constants in your application domain, which will typically be of type Duration. In addition, use a more descriptive name for the method used to parse String values on the form "1 hours", "42 seconds", etc. Deprecating JsonDuration.of(String).
To enforce backwards compatibility. Internal representation has not changed in JsonDuration.
eivinhb
approved these changes
Mar 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Construct JsonDuration from a Duration
Add a factory method
JsonDuration.from(Duration)which "deconstructs" a given Duration into an amount and an appropriate ChronoUnit. The largest possible unit (up to "days") which can be used to accurately represent the duration is chosen.This allows the use of
MY_SENSIBLE_DEFAULTto be used as a default value for aJsonDuration.Previously, the only way to create an instance of
JsonDurationwas to parse a String like"24 hours","4 seconds", etc.More descriptive factory method
Introducing
JsonDuration.parse(String)for parsing a duration, and deprecatingJsonDuration.of(String).Compatibility Report
Summary
Note
No incompatible changes found while checking backward compatibility of version
n.a.-SNAPSHOTwith the previous version4.0.0.Expand to see options used.
PROTECTEDONE_COMMON_CLASSPATH