[Java] fix Jackson 3 createDefaultMapper(null) losing the default date format (restclient, webclient) - #24625
Open
SubhamAshok wants to merge 1 commit into
Conversation
…e format (restclient, webclient)
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 #24588
With
useJackson3=true, the Jackson 3 branch ofcreateDefaultMapperpasses a nullDateFormatstraight intoJsonMapper.builder().defaultDateFormat(dateFormat). The Jackson 2 branch of the same template falls back tocreateDefaultDateFormat()when the argument is null. The generator's own entry points (buildRestClientBuilder(),buildRestClient()) callcreateDefaultMapper(null), so nothing clearsWRITE_DATES_AS_TIMESTAMPSanddate-timefields serialize as epoch numbers instead of RFC 3339.Verified against Jackson 3.1.5 with an exact copy of the generated method:
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 3createDefaultMapperJavaClientCodegenTest#testJackson3DefaultMapperFallsBackToDefaultDateFormat_issue_24588(both libraries)Tested: JavaClientCodegenTest 273/273 green.
PR checklist
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=trueby makingcreateDefaultMapper(null)fall back to the default date format in Javarestclientandwebclient. Date-times now serialize as RFC 3339 strings instead of epoch numbers. Fixes #24588.createDefaultMapper, usecreateDefaultDateFormat()whendateFormatis null (parity with Jackson 2).JavaClientCodegenTest#testJackson3DefaultMapperFallsBackToDefaultDateFormat_issue_24588.Written for commit da0732b. Summary will update on new commits.