Skip to content

[Java] fix Jackson 3 createDefaultMapper(null) losing the default date format (restclient, webclient) - #24625

Open
SubhamAshok wants to merge 1 commit into
OpenAPITools:masterfrom
SubhamAshok:fix/24588-jackson3-default-dateformat
Open

[Java] fix Jackson 3 createDefaultMapper(null) losing the default date format (restclient, webclient)#24625
SubhamAshok wants to merge 1 commit into
OpenAPITools:masterfrom
SubhamAshok:fix/24588-jackson3-default-dateformat

Conversation

@SubhamAshok

@SubhamAshok SubhamAshok commented Aug 5, 2026

Copy link
Copy Markdown

Fixes #24588

With useJackson3=true, the Jackson 3 branch of createDefaultMapper passes a null DateFormat straight into JsonMapper.builder().defaultDateFormat(dateFormat). The Jackson 2 branch of the same template falls back to createDefaultDateFormat() when the argument is null. The generator's own entry points (buildRestClientBuilder(), buildRestClient()) call createDefaultMapper(null), so nothing clears WRITE_DATES_AS_TIMESTAMPS and date-time fields serialize as epoch numbers instead of RFC 3339.

Verified against Jackson 3.1.5 with an exact copy of the generated method:

createDefaultMapper(null), master : {"clientId":"client-1","issuedAt":1785605400.000000000}
createDefaultMapper(null), fixed  : {"clientId":"client-1","issuedAt":"2026-08-01T17:30:00Z"}

The fix adds the same null fallback the Jackson 2 branch already has. The webclient template has the identical bug (same createDefaultMapper(null) call sites, same missing fallback), so it gets the same 3 lines.

Not touched: #24587 (missing message converters) is a separate bug in the same file and will get its own PR.

Changes:

  • Java/libraries/restclient/ApiClient.mustache, Java/libraries/webclient/ApiClient.mustache: null fallback in the Jackson 3 createDefaultMapper
  • Regression test JavaClientCodegenTest#testJackson3DefaultMapperFallsBackToDefaultDateFormat_issue_24588 (both libraries)
  • Regenerated the 4 affected sample configs (java-restclient/webclient-springBoot4-jackson3, plus jspecify variants), 3 lines each, no other drift

Tested: JavaClientCodegenTest 273/273 green.

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    Commit all changed files.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Java technical committee: @bbdouglas @sreeshas @jfiala @lukoyanov @cbornet @jeff9finger @karismann @Zomzog @lwlee2608 @martin-mfg @KannaKim


Summary by cubic

Fixes incorrect date-time serialization when useJackson3=true by making createDefaultMapper(null) fall back to the default date format in Java restclient and webclient. Date-times now serialize as RFC 3339 strings instead of epoch numbers. Fixes #24588.

  • Bug Fixes
    • In the Jackson 3 branch of createDefaultMapper, use createDefaultDateFormat() when dateFormat is null (parity with Jackson 2).
    • Added regression test: JavaClientCodegenTest#testJackson3DefaultMapperFallsBackToDefaultDateFormat_issue_24588.
    • Regenerated affected samples (restclient/webclient Spring Boot 4 + Jackson 3, including jspecify).

Written for commit da0732b. Summary will update on new commits.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 7 files

Re-trigger cubic

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.

[BUG][JAVA][restclient] useJackson3: createDefaultMapper(null) drops the default DateFormat, so date-time fields serialize as epoch numbers

1 participant