Skip to content

Fix #232: add JavaTimeFeature.ALLOW_STRINGIFIED_DURATION_VALUES - #388

Open
arimu1 wants to merge 1 commit into
FasterXML:2.xfrom
arimu1:fix/232-stringified-duration
Open

Fix #232: add JavaTimeFeature.ALLOW_STRINGIFIED_DURATION_VALUES#388
arimu1 wants to merge 1 commit into
FasterXML:2.xfrom
arimu1:fix/232-stringified-duration

Conversation

@arimu1

@arimu1 arimu1 commented Aug 22, 2026

Copy link
Copy Markdown

Fixes #232

Root cause

DurationDeserializer parses JSON Strings with Duration.parse, which only accepts ISO-8601 (PT…). Int-like Strings such as "3600" (OAuth expires_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:

  • integers use @JsonFormat unit conversion / READ_DATE_TIMESTAMPS_AS_NANOSECONDS
  • decimals use seconds with fractional nanos (same as JSON floats)

ISO-8601 duration Strings remain accepted either way.

Enable with:

JsonMapper.builder()
    .addModule(new JavaTimeModule()
        .enable(JavaTimeFeature.ALLOW_STRINGIFIED_DURATION_VALUES))
    .build();

Test plan

  • DurationDeser232Test (10 tests) — default still fails "3600"; feature-on accepts "3600" / "-3600" / "60.5"; @JsonFormat(pattern="SECONDS") applies only when enabled
  • Neighbors: DurationDeserTest, DurationDeser337Test, InstantDeser291Test
  • Full mvn -pl datetime test on JDK 21 Temurin: 1143 tests, 0 fail, 1 skip

AI-assisted (Grok 4.6); human-reviewed.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deserialize Duration from int-like String (e.g. "3600")

1 participant