[java][webclient] Jackson3 support for webclient#23072
[java][webclient] Jackson3 support for webclient#23072robinmarechal wants to merge 6 commits intoOpenAPITools:masterfrom
Conversation
There was a problem hiding this comment.
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-aiwith guidance or docs links (includingllms.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> |
There was a problem hiding this comment.
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>
There was a problem hiding this comment.
OpenAPITools/jackson-databind-nullable#117 required to fix this
There was a problem hiding this comment.
OpenAPITools/jackson-databind-nullable#117 required to fix this
Great work on this contribution!
In the Spring generator, there was the same block with Openapinullable, and what was done was that, for now, useJackson3 and openapiNullable are incompatible.
I think that to unblock this PR, we could do the same thing.
What do you think @robinmarechal @wing328 ?
There was a problem hiding this comment.
That's a good idea!
A just rebased onto master, someone actually did it for me in #23023 😄
modules/openapi-generator/src/main/resources/Java/libraries/webclient/pom.mustache
Show resolved
Hide resolved
modules/openapi-generator/src/main/resources/Java/libraries/webclient/build.gradle.mustache
Show resolved
Hide resolved
modules/openapi-generator/src/main/resources/Java/libraries/webclient/build.gradle.mustache
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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>
| @@ -0,0 +1,10 @@ | |||
| generatorName: java | |||
| outputDir: samples/client/petstore/java/webclient-jackson3 | |||
There was a problem hiding this comment.
I tested this locally with mvn integration-test -f samples/client/petstore/java/webclient-jackson3/pom.xml but got errors:
[ERROR] /C:/Users/User/code/openapi-generator/samples/client/petstore/java/webclient-jackson3/src/main/java/org/openapitools/client/RFC3339JavaTimeModule.java:[28,9] method addDeserializer in class tools.jackson.databind.module.SimpleModule cannot be applied to given types;
[ERROR] required: java.lang.Class<T>,tools.jackson.databind.ValueDeserializer<? extends T>
[ERROR] found: java.lang.Class<java.time.OffsetDateTime>,org.openapitools.client.RFC3339InstantDeserializer<java.time.OffsetDateTime>
[ERROR] reason: cannot infer type-variable(s) T
[ERROR] (argument mismatch; org.openapitools.client.RFC3339InstantDeserializer<java.time.OffsetDateTime> cannot be converted to tools.jackson.databind.ValueDeserializer<? extends T>)
[ERROR] /C:/Users/User/code/openapi-generator/samples/client/petstore/java/webclient-jackson3/src/main/java/org/openapitools/client/RFC3339JavaTimeModule.java:[29,9] method addDeserializer in class tools.jackson.databind.module.SimpleModule cannot be applied to given types;
[ERROR] required: java.lang.Class<T>,tools.jackson.databind.ValueDeserializer<? extends T>
[ERROR] found: java.lang.Class<java.time.ZonedDateTime>,org.openapitools.client.RFC3339InstantDeserializer<java.time.ZonedDateTime>
[ERROR] reason: cannot infer type-variable(s) T
[ERROR] (argument mismatch; org.openapitools.client.RFC3339InstantDeserializer<java.time.ZonedDateTime> cannot be converted to tools.jackson.databind.ValueDeserializer<? extends T>)
can you please take a look when you've time?
please also add this output folder to github workflow: https://github.com/OpenAPITools/openapi-generator/blob/master/.github/workflows/samples-java-client-jdk17.yaml
e25ba6a to
68dc149
Compare
|
Sorry for the close/reopen, small mistake with my rebase. |
There was a problem hiding this comment.
10 issues found across 215 files (changes from recent commits).
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/ApiClient.mustache">
<violation number="1" location="modules/openapi-generator/src/main/resources/Java/libraries/webclient/ApiClient.mustache:13">
P2: Jackson 3 JsonMapper is in tools.jackson.databind.json, not tools.jackson.databind. This import will not resolve and generated clients will fail to compile when useJackson3=true.</violation>
</file>
<file name="samples/client/petstore/java/webclient-jackson3/.travis.yml">
<violation number="1" location="samples/client/petstore/java/webclient-jackson3/.travis.yml:8">
P2: CI matrix uses JDK 8–12, but this sample depends on Spring Boot 4.0.3 which requires Java 17+. Builds/tests will fail or be misleading on those JDKs.</violation>
</file>
<file name="samples/client/petstore/java/webclient-jackson3/docs/PetApi.md">
<violation number="1" location="samples/client/petstore/java/webclient-jackson3/docs/PetApi.md:264">
P3: The example declares a Set<String> but initializes it with Arrays.asList(), which returns a List. This snippet will not compile as written.</violation>
</file>
<file name="docs/generators/java-microprofile.md">
<violation number="1" location="docs/generators/java-microprofile.md:102">
P3: Duplicate `useJackson3` entry in the config options table provides conflicting constraints for the same option, which can mislead users and should be consolidated into a single description.</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: The new build.sbt contains a shell-style “#” comment, which is invalid Scala syntax and will cause SBT to fail parsing this build file.</violation>
</file>
<file name="samples/client/petstore/java/webclient-jackson3/git_push.sh">
<violation number="1" location="samples/client/petstore/java/webclient-jackson3/git_push.sh:48">
P2: GIT_TOKEN is embedded directly in the remote URL, which persists the token in plaintext in .git/config and exposes it in process arguments. Use credential helpers or other non-URL-based auth to avoid leaking the token.</violation>
</file>
<file name="samples/client/petstore/java/webclient-jackson3/docs/FakeApi.md">
<violation number="1" location="samples/client/petstore/java/webclient-jackson3/docs/FakeApi.md:1007">
P2: The generated Java example uses `Arrays.asList(-efg)`, which is invalid Java syntax and makes the snippet uncompilable.</violation>
</file>
<file name="samples/client/petstore/java/webclient-jackson3/build.gradle">
<violation number="1" location="samples/client/petstore/java/webclient-jackson3/build.gradle:81">
P2: Spring Boot 4.0 requires Java 17+, but this build sets source/target to Java 8, which will not compile/run with Boot 4 dependencies.</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:196">
P2: When useJackson3 is enabled, the template still always adds jackson-databind-nullable 0.2.9, which is built against Jackson 2.x. This will pull com.fasterxml.jackson.databind 2.x alongside tools.jackson 3.x, leading to classpath/API incompatibilities for openApiNullable users. Consider gating openApiNullable for Jackson3 or upgrading to a Jackson3-compatible nullable module when available.</violation>
</file>
<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:202">
P2: Non-Jakarta mode now picks Spring Boot 4.0.3 when useJackson3 is true, but non-Jakarta templates still generate javax.* imports. Spring Boot 4 is Jakarta-only, so this combination will not compile/run with the generated code and dependency versions.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
modules/openapi-generator/src/main/resources/Java/libraries/webclient/ApiClient.mustache
Outdated
Show resolved
Hide resolved
| echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." | ||
| git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git | ||
| else | ||
| git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@${git_host}/${git_user_id}/${git_repo_id}.git |
There was a problem hiding this comment.
P2: GIT_TOKEN is embedded directly in the remote URL, which persists the token in plaintext in .git/config and exposes it in process arguments. Use credential helpers or other non-URL-based auth to avoid leaking the token.
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/git_push.sh, line 48:
<comment>GIT_TOKEN is embedded directly in the remote URL, which persists the token in plaintext in .git/config and exposes it in process arguments. Use credential helpers or other non-URL-based auth to avoid leaking the token.</comment>
<file context>
@@ -0,0 +1,57 @@
+ echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
+ git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git
+ else
+ git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@${git_host}/${git_user_id}/${git_repo_id}.git
+ fi
+
</file context>
| @@ -131,20 +131,37 @@ ext { | |||
| swagger_annotations_version = "2.2.9" | |||
There was a problem hiding this comment.
P2: When useJackson3 is enabled, the template still always adds jackson-databind-nullable 0.2.9, which is built against Jackson 2.x. This will pull com.fasterxml.jackson.databind 2.x alongside tools.jackson 3.x, leading to classpath/API incompatibilities for openApiNullable users. Consider gating openApiNullable for Jackson3 or upgrading to a Jackson3-compatible nullable module when available.
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/build.gradle.mustache, line 196:
<comment>When useJackson3 is enabled, the template still always adds jackson-databind-nullable 0.2.9, which is built against Jackson 2.x. This will pull com.fasterxml.jackson.databind 2.x alongside tools.jackson 3.x, leading to classpath/API incompatibilities for openApiNullable users. Consider gating openApiNullable for Jackson3 or upgrading to a Jackson3-compatible nullable module when available.</comment>
<file context>
@@ -166,17 +183,25 @@ dependencies {
+ {{#useJackson3}}
+ implementation "tools.jackson.core:jackson-core:$jackson_version"
+ implementation "tools.jackson.jaxrs:jackson-jaxrs-json-provider:$jackson_version"
+ implementation "tools.jackson.core:jackson-databind:$jackson_databind_version"
+ implementation "com.fasterxml.jackson.core:jackson-annotations:$jackson_annotations_version"
+ {{/useJackson3}}
</file context>
| <spring-boot-version>3.2.12</spring-boot-version> | ||
| {{/useJackson3}} | ||
| {{#useJackson3}} | ||
| <spring-boot-version>4.0.3</spring-boot-version> |
There was a problem hiding this comment.
P2: Non-Jakarta mode now picks Spring Boot 4.0.3 when useJackson3 is true, but non-Jakarta templates still generate javax.* imports. Spring Boot 4 is Jakarta-only, so this combination will not compile/run with the generated code and dependency versions.
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>Non-Jakarta mode now picks Spring Boot 4.0.3 when useJackson3 is true, but non-Jakarta templates still generate javax.* imports. Spring Boot 4 is Jakarta-only, so this combination will not compile/run with the generated code and dependency versions.</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>
| petstore_auth.setAccessToken("YOUR ACCESS TOKEN"); | ||
|
|
||
| PetApi apiInstance = new PetApi(defaultClient); | ||
| Set<String> tags = Arrays.asList(); // Set<String> | Tags to filter by |
There was a problem hiding this comment.
P3: The example declares a Set but initializes it with Arrays.asList(), which returns a List. This snippet will not compile as written.
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/docs/PetApi.md, line 264:
<comment>The example declares a Set<String> but initializes it with Arrays.asList(), which returns a List. This snippet will not compile as written.</comment>
<file context>
@@ -0,0 +1,678 @@
+ petstore_auth.setAccessToken("YOUR ACCESS TOKEN");
+
+ PetApi apiInstance = new PetApi(defaultClient);
+ Set<String> tags = Arrays.asList(); // Set<String> | Tags to filter by
+ try {
+ Set<Pet> result = apiInstance.findPetsByTags(tags);
</file context>
There was a problem hiding this comment.
This is caused by AbstractJavaCodegen#setParameterExampleValue(CodegenParameter) because of this code bloc:
if (example == null) {
example = "null";
} else if (Boolean.TRUE.equals(p.isArray)) { // <-- An array can be a Set, eg. if "uniqueItems" is true
if (p.items != null && p.items.defaultValue != null) {
String innerExample;
if ("String".equals(p.items.dataType)) {
innerExample = "\"" + p.items.defaultValue + "\"";
} else {
innerExample = p.items.defaultValue;
}
example = "Arrays.asList(" + innerExample + ")"; // <--- But we unconditionally instanciate it to List
} else {
example = "Arrays.asList()"; // <--- Here as well
}
} else if (Boolean.TRUE.equals(p.isMap)) {
example = "new HashMap()";
}I'll create another PR for that fix as this is not related to webclient and Jackson3
docs/generators/java-microprofile.md
Outdated
| |useGzipFeature|Send gzip-encoded requests| |false| | ||
| |useJackson3|Set it in order to use jackson 3 dependencies (only allowed when `useSpringBoot4` is set and incompatible with `openApiNullable`).| |false| | ||
| |useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false| | ||
| |useJackson3|Use Jackson 3 instead of Jackson 2 for JSON processing. Only supported for 'native' and 'webclient' libraries.| |false| |
There was a problem hiding this comment.
P3: Duplicate useJackson3 entry in the config options table provides conflicting constraints for the same option, which can mislead users and should be consolidated into a single description.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At docs/generators/java-microprofile.md, line 102:
<comment>Duplicate `useJackson3` entry in the config options table provides conflicting constraints for the same option, which can mislead users and should be consolidated into a single description.</comment>
<file context>
@@ -99,6 +99,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|useGzipFeature|Send gzip-encoded requests| |false|
|useJackson3|Set it in order to use jackson 3 dependencies (only allowed when `useSpringBoot4` is set and incompatible with `openApiNullable`).| |false|
|useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false|
+|useJackson3|Use Jackson 3 instead of Jackson 2 for JSON processing. Only supported for 'native' and 'webclient' libraries.| |false|
|useOneOfDiscriminatorLookup|Use the discriminator's mapping in oneOf to speed up the model lookup. IMPORTANT: Validation (e.g. one and only one match in oneOf's schemas) will be skipped. Only jersey2, jersey3, native, okhttp-gson support this option.| |false|
|useOneOfInterfaces|whether to use a java interface to describe a set of oneOf options, where each option is a class that implements the interface| |false|
</file context>
54ccecd to
dc3f2a6
Compare
|
@wing328 this PR is now ready to be re-reviewed. The integration tests are now OK: |
Add Jackson 3 support to webclient.
Equivalent of #23071 for webclient, integrating some of the changes made in it for native client.
Added
useJackson3option, with defaultfalseto keep using jackson 2 as a default.Note : Annotations do not move with jackson 3. Therefore
import com.fasterxml.jackson.annotationdo not change.ApiClient:useJackson3to import either jackson 3 or jackson 2 classesJsonMapper.builder()to create default object mapperObjectMapperinstead ofJsonMapperto simplify jackson 2/3 interoperability in mustache fileJsonProcessingExceptionanymore. Jackson3's object mapper now throwsJacksonExceptionwhich is already aRuntimeException.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
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.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)"fixes #123"present in the PR description)@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 useJackson3 (default false). Standardizes tools.jackson dependencies, updates RFC3339 handling, and adds a CI-validated sample. Fixes #22294.
New Features
Migration
Written for commit 7e306e8. Summary will update on new commits.