Skip to content

feature/jackson3 native (fixes #22294)#23071

Open
thorstenhirsch wants to merge 27 commits intoOpenAPITools:masterfrom
thorstenhirsch:feature/jackson3-native
Open

feature/jackson3 native (fixes #22294)#23071
thorstenhirsch wants to merge 27 commits intoOpenAPITools:masterfrom
thorstenhirsch:feature/jackson3-native

Conversation

@thorstenhirsch
Copy link
Contributor

@thorstenhirsch thorstenhirsch commented Feb 27, 2026

Add Jackson 3 support to java-native.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • 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
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10) @martin-mfg (2023/08)


Summary by cubic

Adds opt-in Jackson 3 support to the Java native client generator while keeping Jackson 2 as default. When enabled, it requires Java 17+, improves RFC3339 date/time handling, and ships a native-jackson3 sample with CI (JDK 17/21).

  • New Features

    • Opt-in useJackson3: dynamic imports via {{jacksonPackage}}; switch to JsonMapper with EnumFeature/DateTimeFeature; adopt SerializationContext; update RFC3339 module/Instant deserializer; better anyOf/oneOf; handle JacksonException; remove unused IOException; fix mapper.copy().
    • Build/CI: Java 17 source/target for Jackson 3; upgrade to Jackson 3.1.0; pin jackson-annotations 2.21; add native-jackson3 sample and include it in JDK 17/21 CI; add JDK HttpClient test; enable JUnit 5 in native/native-async Gradle builds.
    • Docs and samples: document useJackson3 for 'native' and 'restclient' (requires useSpringBoot4=true); clarify 'openApiNullable' incompatibility and note it auto-disables when both are set; fix WithHttpInfo doc signatures; regenerate Java/TypeScript samples; JsonNullable works without jackson-databind-nullable.
  • Migration

    • Default remains Jackson 2. To opt in for 'native', set additionalProperties.useJackson3=true.
    • Requires Java 17+ when using Jackson 3. Regenerate clients; no other changes needed.

Written for commit 4ce631a. Summary will update on new commits.

@thorstenhirsch thorstenhirsch marked this pull request as ready for review February 27, 2026 17:39
Copy link
Contributor

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

Choose a reason for hiding this comment

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

4 issues found across 304 files

Note: This PR contains a large number of files. cubic only reviews up to 75 files per PR, so some files may not have been reviewed.

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="modules/openapi-generator/src/main/resources/Java/libraries/native/pom.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/Java/libraries/native/pom.mustache:268">
P1: Potential compile failure: When useJackson3=true, jackson-databind-nullable dependency is excluded from POM, but pojo.mustache still generates JsonNullable type references if openApiNullable is enabled (default). This causes compilation errors due to missing import org.openapitools.jackson.nullable.JsonNullable.</violation>
</file>

<file name="samples/client/petstore/java/native-jackson3/build.gradle">

<violation number="1" location="samples/client/petstore/java/native-jackson3/build.gradle:87">
P2: JUnit 5 is incompletely configured - missing engine dependency and useJUnitPlatform()</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/Java/libraries/native/model.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/Java/libraries/native/model.mustache:50">
P0: Incorrect Jackson 3 annotation package imports. The `jackson-annotations` module deliberately kept `com.fasterxml.jackson.annotation.*` package in Jackson 3 for backward compatibility - only core modules moved to `tools.jackson.*`. Fix: annotation imports should remain as `com.fasterxml.jackson.annotation.*` in the useJackson3 section.</violation>
</file>

<file name="samples/client/petstore/java/native-jackson3/docs/DefaultApi.md">

<violation number="1" location="samples/client/petstore/java/native-jackson3/docs/DefaultApi.md:73">
P2: Documentation method signature contains extra 'fooGet' token, resulting in invalid Java syntax 'ApiResponse<FooGetDefaultResponse> fooGet fooGetWithHttpInfo()'. Should be 'ApiResponse<FooGetDefaultResponse> fooGetWithHttpInfo()'.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@thorstenhirsch
Copy link
Contributor Author

thorstenhirsch commented Mar 1, 2026

I'm not sure about the JUnit 5 changes in samples/client/... - here's what Claude Sonnet 4.6 says when asked for the reason of these changes:

The sample changes come from two of our template fixes that affect all native library samples, not just the Jackson 3 one:

  1. build.gradle.mustache — we added testRuntimeOnly "junit-jupiter-engine" and test { useJUnitPlatform() } to fix incomplete JUnit 5 configuration. This regenerated
    build.gradle in every native library sample (native-async, echo_api/java/native, etc.).
  2. api_doc.mustache — we removed the duplicate {{operationId}} token from WithHttpInfo method signatures. This regenerated all native library API docs (removing the
    spurious prefix like > fooGet fooGetWithHttpInfo() → > fooGetWithHttpInfo()).

Sounds reasonable to me. If you don't want them here, but in a separate PR instead, I will revert them here, of course.

@thorstenhirsch
Copy link
Contributor Author

Alright, please do another code review @cubic-dev-ai

@cubic-dev-ai
Copy link
Contributor

cubic-dev-ai bot commented Mar 1, 2026

Alright, please do another code review @cubic-dev-ai

@thorstenhirsch I have started the AI code review. It will take a few minutes to complete.

Copy link
Contributor

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

Choose a reason for hiding this comment

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

3 issues found across 333 files

Note: This PR contains a large number of files. cubic only reviews up to 75 files per PR, so some files may not have been reviewed.

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="samples/client/petstore/java/native-jackson3/README.md">

<violation number="1" location="samples/client/petstore/java/native-jackson3/README.md:18">
P1: README incorrectly states Java 11+ requirement but Jackson 3 requires Java 17+. This documentation error will cause build/runtime failures for users following the instructions.</violation>
</file>

<file name="samples/client/petstore/java/native-jackson3/.travis.yml">

<violation number="1" location="samples/client/petstore/java/native-jackson3/.travis.yml:6">
P1: Travis CI uses JDK 11 (oraclejdk11) but Jackson 3.x requires Java 17+</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/Java/libraries/native/ApiClient.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/Java/libraries/native/ApiClient.mustache:4">
P1: JsonNullableModule is not registered when useJackson3 is enabled, breaking JsonNullable (de)serialization for models generated with openApiNullable=true</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@thorstenhirsch
Copy link
Contributor Author

Sorry, this PR is still not ready. The generated code contains wrong imports. I'm working on it.

@thorstenhirsch
Copy link
Contributor Author

Alright, I've fixed SerializerProvider/SerializationContext, ObjectMapper/JsonMapper issues and error handling with the new JacksonException. Now I could successfully generate a Java client with Jackson 3, all unit tests succeed. Also, I've made sure that Jackson 2 still works.

Now I guess it's finally time to start with human code reviews. And sorry @robinmarechal that I've asked you too early and wasted your time.

@@ -0,0 +1,11 @@
generatorName: java
outputDir: samples/client/petstore/java/native-jackson3
Copy link
Member

Choose a reason for hiding this comment

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

i did a test with mvn integration-test -f samples/client/petstore/java/native-jackson3/pom.xml but resulted in errors, e..g

[ERROR] /C:/Users/User/code/openapi-generator/samples/client/petstore/java/native-jackson3/src/test/java/org/openapitools/client/model/EnumTestTest.java:[21,41] package org.openapitools.jackson.nullable does not exist
[ERROR] /C:/Users/User/code/openapi-generator/samples/client/petstore/java/native-jackson3/src/test/java/org/openapitools/client/model/EnumTestTest.java:[27,41] package org.openapitools.jackson.nullable does not exist
[ERROR] /C:/Users/User/code/openapi-generator/samples/client/petstore/java/native-jackson3/src/test/java/org/openapitools/client/api/FakeApiTest.java:[320,16] cannot find symbol
[ERROR]   symbol:   class APItestGroupParametersRequest
[ERROR]   location: class org.openapitools.client.api.FakeApi
[ERROR] /C:/Users/User/code/openapi-generator/samples/client/petstore/java/native-jackson3/src/test/java/org/openapitools/client/api/FakeApiTest.java:[320,64] cannot find symbol

can you please take a look when you've time?

also please add this folder to the github workflow: https://github.com/OpenAPITools/openapi-generator/blob/master/.github/workflows/samples-java-client-jdk17.yaml

@thorstenhirsch
Copy link
Contributor Author

Lots of getters and setters missing in modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenModel.java after I've merged master into this feature branch. Looks like I now need to respect useSpringBoot4, as well. Let me give it a shot ...

Copy link
Contributor

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

Choose a reason for hiding this comment

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

1 issue found across 66 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="docs/generators/java.md">

<violation number="1" location="docs/generators/java.md:100">
P2: Documentation for useJackson3 with 'native' library is missing Java 17 requirement. Jackson 3 requires Java 17 but the documentation only mentions 'native' library requires Java 11+, misleading users who may attempt to use useJackson3 on Java 11-16.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@thorstenhirsch
Copy link
Contributor Author

Alright, this branch is now aligned with restclient's Jackson 3.1.0, unit tests and the integration test you mentioned succeed. @wing328

Copy link
Contributor

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

Choose a reason for hiding this comment

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

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="docs/generators/java-microprofile.md">

<violation number="1" location="docs/generators/java-microprofile.md:100">
P2: Documentation regression: The `useJackson3` option description removes the incompatibility warning for `openApiNullable`, but the generator code (`JavaClientCodegen.java`) still silently disables `openApiNullable` when both options are enabled. This creates a documentation-to-implementation contract mismatch where users expect the combination to work but won't get the expected nullable functionality in generated code.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>

Choose a reason for hiding this comment

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

Was this file pushed by error?

cliOptions.add(CliOption.newBoolean(SUPPORT_URL_QUERY, "Generate toUrlQueryString in POJO (default to true). Available on `native`, `apache-httpclient` libraries."));
cliOptions.add(CliOption.newBoolean(USE_ENUM_CASE_INSENSITIVE, "Use `equalsIgnoreCase` when String for enum comparison", useEnumCaseInsensitive));
cliOptions.add(CliOption.newBoolean(FAIL_ON_UNKNOWN_PROPERTIES, "Fail Jackson de-serialization on unknown properties", this.failOnUnknownProperties));
cliOptions.add(CliOption.newBoolean(USE_JACKSON_3, "Use Jackson 3 instead of Jackson 2. Supported for 'native' library (requires Java 17+) and for 'restclient' library (requires useSpringBoot4=true).", this.useJackson3));

Choose a reason for hiding this comment

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

A PR implementing useJackson3 for restclient has already been merged to master. cf. #23023.
These attributes, cliOptions, etc... already exists in master.

I think you should update your branch ans use what already exists 🙂

if (useJackson3 && libRestClient && !useSpringBoot4) {
throw new IllegalArgumentException("useJackson3 for the restclient library requires useSpringBoot4=true");
} else if (useJackson3 && !libNative && !libRestClient) {
LOGGER.warn("useJackson3 is only supported for 'native' and 'restclient' libraries. Disabling useJackson3.");

Choose a reason for hiding this comment

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

I think silently disabling a feature is not the right thing to do (even if its logged as a warning, one warning in thousands of lines can be almost invisible).

I'd personnally prefer that the generation fails with a clear error message, telling my to explicitly set an option in my config, instead of an unexpected behavior because i didn't see this specific warning.

And that's what has been done for openApiNullable in #23023 which has already been merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants