Skip to content

[java][webclient] Jackson3 support for webclient#23072

Open
robinmarechal wants to merge 3 commits intoOpenAPITools:masterfrom
robinmarechal:feature/jackson3-webclient
Open

[java][webclient] Jackson3 support for webclient#23072
robinmarechal wants to merge 3 commits intoOpenAPITools:masterfrom
robinmarechal:feature/jackson3-webclient

Conversation

@robinmarechal
Copy link

@robinmarechal robinmarechal commented Feb 28, 2026

Add Jackson 3 support to webclient.
Equivalent of #23071 for webclient, integrating some of the changes made in it for native client.

Added useJackson3 option, with default false to keep using jackson 2 as a default.
Note : Annotations do not move with jackson 3. Therefore import com.fasterxml.jackson.annotation do not change.

  • Main changes are in ApiClient :
    • Use useJackson3 to import either jackson 3 or jackson 2 classes
    • Use JsonMapper.builder() to create default object mapper
    • No equivalent of JavaTimeModule since it has been included directly in jackson databind
    • Keep ObjectMapper instead of JsonMapper to simplify jackson 2/3 interoperability in mustache file
    • Change codecs to use Jackson 3 instead of jackson 2 encoder/decoder. Without specifying media type myself because Spring does a better job than us to use json-compatible media types by default (I run into errors when I tried to specify it myself as before, which were fixed when removing it)
    • No need for try/catch JsonProcessingException anymore. Jackson3's object mapper now throws JacksonException which is already a RuntimeException.

fixes #22294

Ideally, OpenAPITools/jackson-databind-nullable#117 would be merged before so I can update its version in maven/gradle dependencies. But it can also be done afterwards.

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 optional Jackson 3 support to the Java WebClient generator via the useJackson3 flag, keeping Jackson 2 as the default. Also standardizes and fixes Jackson dependency coordinates/versions in Gradle/Maven templates and samples. Fixes #22294.

  • New Features

    • Added useJackson3 (default false) to switch WebClient JSON handling to Jackson 3.
    • ApiClient uses JsonMapper.builder and JacksonException; keeps ObjectMapper for 2/3 compatibility.
    • RFC3339 date/time updated with custom deserializers; JavaTimeModule no longer required.
    • WebClient codecs use Jackson 3 encoder/decoder with Spring auto media-type selection.
    • Nullable support uses JsonNullableJackson3Module when enabled.
    • Docs updated and a webclient-jackson3 sample with CI added; test covers Jackson 3 generation.
  • Migration

    • Opt in with additionalProperties.useJackson3: true.
    • Requires Jackson 3.x (tools.jackson.* artifacts) and Spring Boot 4.x on generated projects.
    • Annotations remain under com.fasterxml.jackson.annotation; no changes needed.
    • No need to catch JsonProcessingException; Jackson 3 throws JacksonException (runtime).
    • Templates now standardize jackson-version and groupIds; removed extra jackson-databind-version in samples; Spring Boot set to 4.0.3 when useJackson3.

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

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.

6 issues found across 224 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/webclient/pom.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/Java/libraries/webclient/pom.mustache:126">
P2: Using Jackson 3 with openApiNullable pulls in jackson-databind-nullable 0.2.9, which only provides the Jackson 2 module (JsonNullableModule). The generated ApiClient uses JsonNullableJackson3Module under useJackson3, so the code will not compile.</violation>

<violation number="2" location="modules/openapi-generator/src/main/resources/Java/libraries/webclient/pom.mustache:202">
P2: Spring Boot 4.x (Jakarta-based) is configured in the useJakartaEe=false block, which is intended for legacy javax compatibility. This makes the non-Jakarta configuration incompatible with its own goal and will break builds expecting javax.* APIs.</violation>
</file>

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

<violation number="1" location="samples/client/petstore/java/webclient-jackson3/build.gradle:123">
P2: `jackson_databind_version` is assigned twice; the second assignment overwrites the intended Jackson 3 version with 2.19.2, causing the `tools.jackson.core:jackson-databind` dependency to resolve to a non-existent/incorrect version.</violation>
</file>

<file name="samples/client/petstore/java/webclient-jackson3/build.sbt">

<violation number="1" location="samples/client/petstore/java/webclient-jackson3/build.sbt:1">
P2: Invalid `#` comment syntax in build.sbt will cause sbt to fail parsing the build file.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/Java/libraries/webclient/build.gradle.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/Java/libraries/webclient/build.gradle.mustache:162">
P2: jackson_databind_version is set to 3.1.0 for useJackson3, but an unconditional assignment to 2.19.2 later in the file overwrites it, so the Jackson 3 dependency block still uses the 2.x version.</violation>

<violation number="2" location="modules/openapi-generator/src/main/resources/Java/libraries/webclient/build.gradle.mustache:194">
P2: openApiNullable pulls in Jackson 2 (jackson-databind-nullable) even when useJackson3 switches to tools.jackson dependencies, leading to a mixed Jackson 2/3 classpath and broken JsonNullable support.</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Add one-off context when rerunning by tagging @cubic-dev-ai with guidance or docs links (including llms.txt)
  • Ask questions if you need clarification on any suggestion

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

{{/useJackson3}}
{{#useJackson3}}
<dependency>
<groupId>tools.jackson.core</groupId>
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Feb 28, 2026

Choose a reason for hiding this comment

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

P2: Using Jackson 3 with openApiNullable pulls in jackson-databind-nullable 0.2.9, which only provides the Jackson 2 module (JsonNullableModule). The generated ApiClient uses JsonNullableJackson3Module under useJackson3, so the code will not compile.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/Java/libraries/webclient/pom.mustache, line 126:

<comment>Using Jackson 3 with openApiNullable pulls in jackson-databind-nullable 0.2.9, which only provides the Jackson 2 module (JsonNullableModule). The generated ApiClient uses JsonNullableJackson3Module under useJackson3, so the code will not compile.</comment>

<file context>
@@ -114,11 +114,20 @@
+        {{/useJackson3}}
+        {{#useJackson3}}
+        <dependency>
+            <groupId>tools.jackson.core</groupId>
+            <artifactId>jackson-databind</artifactId>
+            <version>${jackson-databind-version}</version>
</file context>
Fix with Cubic

Copy link
Author

Choose a reason for hiding this comment

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

<spring-boot-version>3.2.12</spring-boot-version>
{{/useJackson3}}
{{#useJackson3}}
<spring-boot-version>4.0.3</spring-boot-version>
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Feb 28, 2026

Choose a reason for hiding this comment

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

P2: Spring Boot 4.x (Jakarta-based) is configured in the useJakartaEe=false block, which is intended for legacy javax compatibility. This makes the non-Jakarta configuration incompatible with its own goal and will break builds expecting javax.* APIs.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/Java/libraries/webclient/pom.mustache, line 202:

<comment>Spring Boot 4.x (Jakarta-based) is configured in the useJakartaEe=false block, which is intended for legacy javax compatibility. This makes the non-Jakarta configuration incompatible with its own goal and will break builds expecting javax.* APIs.</comment>

<file context>
@@ -167,19 +183,35 @@
         <spring-boot-version>3.2.12</spring-boot-version>
+        {{/useJackson3}}
+        {{#useJackson3}}
+        <spring-boot-version>4.0.3</spring-boot-version>
+        {{/useJackson3}}
         <jakarta-annotation-version>2.1.1</jakarta-annotation-version>
</file context>
Suggested change
<spring-boot-version>4.0.3</spring-boot-version>
<spring-boot-version>2.7.17</spring-boot-version>
Fix with Cubic

@@ -0,0 +1 @@
# TODO
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Feb 28, 2026

Choose a reason for hiding this comment

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

P2: Invalid # comment syntax in build.sbt will cause sbt to fail parsing the build file.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/java/webclient-jackson3/build.sbt, line 1:

<comment>Invalid `#` comment syntax in build.sbt will cause sbt to fail parsing the build file.</comment>

<file context>
@@ -0,0 +1 @@
+# TODO
</file context>
Fix with Cubic

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 20 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="modules/openapi-generator/src/main/resources/Java/libraries/webclient/pom.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/Java/libraries/webclient/pom.mustache:121">
P2: openApiNullable still adds jackson-databind-nullable (Jackson 2) even when useJackson3 is enabled, creating a Jackson 2/3 dependency mismatch that breaks generated clients. Guard openApiNullable for Jackson 3 or use a Jackson 3–compatible nullable module.</violation>
</file>

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

<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-databind-version}</version>
<version>${jackson-version}</version>
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Feb 28, 2026

Choose a reason for hiding this comment

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

P2: openApiNullable still adds jackson-databind-nullable (Jackson 2) even when useJackson3 is enabled, creating a Jackson 2/3 dependency mismatch that breaks generated clients. Guard openApiNullable for Jackson 3 or use a Jackson 3–compatible nullable module.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/resources/Java/libraries/webclient/pom.mustache, line 121:

<comment>openApiNullable still adds jackson-databind-nullable (Jackson 2) even when useJackson3 is enabled, creating a Jackson 2/3 dependency mismatch that breaks generated clients. Guard openApiNullable for Jackson 3 or use a Jackson 3–compatible nullable module.</comment>

<file context>
@@ -118,14 +118,14 @@
             <groupId>com.fasterxml.jackson.core</groupId>
             <artifactId>jackson-databind</artifactId>
-            <version>${jackson-databind-version}</version>
+            <version>${jackson-version}</version>
         </dependency>
         {{/useJackson3}}
</file context>
Fix with 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.

[REQ] Jackson3 support for java libraries

1 participant