Fix #232: add JavaTimeFeature.ALLOW_STRINGIFIED_DURATION_VALUES - #388
Open
arimu1 wants to merge 1 commit into
Open
Fix #232: add JavaTimeFeature.ALLOW_STRINGIFIED_DURATION_VALUES#388arimu1 wants to merge 1 commit into
arimu1 wants to merge 1 commit into
Conversation
Opt-in Duration deserialization from JSON stringified numbers such as "3600", using the same numeric path as JSON numbers. Default remains ISO-8601 Duration.parse only.
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.
Fixes #232
Root cause
DurationDeserializerparses JSON Strings withDuration.parse, which only accepts ISO-8601 (PT…). Int-like Strings such as"3600"(OAuthexpires_in) fail even when@JsonFormat(pattern = "SECONDS")is present, because that annotation only applies to JSON numbers.Change
Add
JavaTimeFeature.ALLOW_STRINGIFIED_DURATION_VALUES(default off, so existing behavior is unchanged). When enabled, integer and decimal numeric Strings are handled the same as JSON numbers:@JsonFormatunit conversion /READ_DATE_TIMESTAMPS_AS_NANOSECONDSISO-8601 duration Strings remain accepted either way.
Enable with:
Test plan
DurationDeser232Test(10 tests) — default still fails"3600"; feature-on accepts"3600"/"-3600"/"60.5";@JsonFormat(pattern="SECONDS")applies only when enabledDurationDeserTest,DurationDeser337Test,InstantDeser291Testmvn -pl datetime teston JDK 21 Temurin: 1143 tests, 0 fail, 1 skipAI-assisted (Grok 4.6); human-reviewed.