feature/jackson3 native (fixes #22294)#23071
feature/jackson3 native (fixes #22294)#23071thorstenhirsch wants to merge 2 commits intoOpenAPITools:masterfrom
Conversation
There was a problem hiding this comment.
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.
| {{/vendorExtensions.x-has-readonly-properties}} | ||
| {{/useJackson3}} | ||
| {{#useJackson3}} | ||
| import tools.jackson.annotation.JsonPropertyOrder; |
There was a problem hiding this comment.
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.
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/native/model.mustache, line 50:
<comment>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.</comment>
<file context>
@@ -31,13 +37,24 @@ import {{import}};
{{/vendorExtensions.x-has-readonly-properties}}
+{{/useJackson3}}
+{{#useJackson3}}
+import tools.jackson.annotation.JsonPropertyOrder;
+{{#withXml}}
+import tools.jackson.dataformat.xml.annotation.*;
</file context>
| <artifactId>jackson-datatype-jsr310</artifactId> | ||
| <version>${jackson3-version}</version> | ||
| </dependency> | ||
| <!-- Note: jackson-databind-nullable is not yet available for Jackson 3 --> |
There was a problem hiding this comment.
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.
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/native/pom.mustache, line 268:
<comment>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.</comment>
<file context>
@@ -242,6 +243,30 @@
+ <artifactId>jackson-datatype-jsr310</artifactId>
+ <version>${jackson3-version}</version>
+ </dependency>
+ <!-- Note: jackson-databind-nullable is not yet available for Jackson 3 -->
+ {{/useJackson3}}
</file context>
| implementation "jakarta.annotation:jakarta.annotation-api:$jakarta_annotation_version" | ||
| implementation "org.apache.httpcomponents:httpmime:$httpmime_version" | ||
| implementation "org.apache.commons:commons-lang3:$commons_lang3_version" | ||
| testImplementation "org.junit.jupiter:junit-jupiter-api:$junit_version" |
There was a problem hiding this comment.
P2: JUnit 5 is incompletely configured - missing engine dependency and useJUnitPlatform()
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/java/native-jackson3/build.gradle, line 87:
<comment>JUnit 5 is incompletely configured - missing engine dependency and useJUnitPlatform()</comment>
<file context>
@@ -0,0 +1,111 @@
+ implementation "jakarta.annotation:jakarta.annotation-api:$jakarta_annotation_version"
+ implementation "org.apache.httpcomponents:httpmime:$httpmime_version"
+ implementation "org.apache.commons:commons-lang3:$commons_lang3_version"
+ testImplementation "org.junit.jupiter:junit-jupiter-api:$junit_version"
+}
+
</file context>
|
|
||
| ## fooGetWithHttpInfo | ||
|
|
||
| > ApiResponse<FooGetDefaultResponse> fooGet fooGetWithHttpInfo() |
There was a problem hiding this comment.
P2: Documentation method signature contains extra 'fooGet' token, resulting in invalid Java syntax 'ApiResponse fooGet fooGetWithHttpInfo()'. Should be 'ApiResponse fooGetWithHttpInfo()'.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/java/native-jackson3/docs/DefaultApi.md, line 73:
<comment>Documentation method signature contains extra 'fooGet' token, resulting in invalid Java syntax 'ApiResponse<FooGetDefaultResponse> fooGet fooGetWithHttpInfo()'. Should be 'ApiResponse<FooGetDefaultResponse> fooGetWithHttpInfo()'.</comment>
<file context>
@@ -0,0 +1,132 @@
+
+## fooGetWithHttpInfo
+
+> ApiResponse<FooGetDefaultResponse> fooGet fooGetWithHttpInfo()
+
+
</file context>
| importMapping.put("JsonProperty", "tools.jackson.annotation.JsonProperty"); | ||
| importMapping.put("JsonSubTypes", "tools.jackson.annotation.JsonSubTypes"); | ||
| importMapping.put("JsonTypeInfo", "tools.jackson.annotation.JsonTypeInfo"); | ||
| importMapping.put("JsonTypeName", "tools.jackson.annotation.JsonTypeName"); | ||
| importMapping.put("JsonCreator", "tools.jackson.annotation.JsonCreator"); | ||
| importMapping.put("JsonValue", "tools.jackson.annotation.JsonValue"); | ||
| importMapping.put("JsonIgnore", "tools.jackson.annotation.JsonIgnore"); | ||
| importMapping.put("JsonIgnoreProperties", "tools.jackson.annotation.JsonIgnoreProperties"); | ||
| importMapping.put("JsonInclude", "tools.jackson.annotation.JsonInclude"); | ||
| importMapping.put("JsonDeserialize", "tools.jackson.databind.annotation.JsonDeserialize"); | ||
| importMapping.put("JsonFormat", "tools.jackson.annotation.JsonFormat"); | ||
| // Secondary rule: when JsonProperty is imported, also import JsonCreator (Jackson 3) | ||
| importMapping.put("tools.jackson.annotation.JsonProperty", "tools.jackson.annotation.JsonCreator"); |
There was a problem hiding this comment.
Annotations are still in package com.fasterxml.annotation: https://github.com/FasterXML/jackson/wiki/Jackson-Release-3.0#annotations
I think you should remove this entire importMapping.put section
| implementation "tools.jackson.core:jackson-core:$jackson3_version" | ||
| implementation "tools.jackson.core:jackson-annotations:$jackson3_version" | ||
| implementation "tools.jackson.core:jackson-databind:$jackson3_version" | ||
| implementation "tools.jackson.datatype:jackson-datatype-jsr310:$jackson3_version" |
There was a problem hiding this comment.
Jackson team decided to not make a Jackson 3 version of module jackson-datatype-jsr310.
They included directly in datatabind instead.
This dependency does and will not exist for Jackson 3 (abandonned after rc2 and included directly in databind).
| {{/useJackson3}} | ||
| {{#useJackson3}} | ||
| implementation "tools.jackson.core:jackson-core:$jackson3_version" | ||
| implementation "tools.jackson.core:jackson-annotations:$jackson3_version" |
There was a problem hiding this comment.
Jackson 3 still uses "old" jackson-annotations module.
You need to import com.fasterxml.jackson.core:jackson-annotations, but with 2.x version
| <dependency> | ||
| <groupId>tools.jackson.core</groupId> | ||
| <artifactId>jackson-annotations</artifactId> | ||
| <version>${jackson3-version}</version> | ||
| </dependency> |
There was a problem hiding this comment.
Cf. build.gradle.mustache.
tools.jackson.core:jackson-annotations:3.x does not exist.
You should use com.fasterxml.jackson.core:jackson-annotations:2.x even for Jackson 3
| <dependency> | ||
| <groupId>tools.jackson.datatype</groupId> | ||
| <artifactId>jackson-datatype-jsr310</artifactId> | ||
| <version>${jackson3-version}</version> | ||
| </dependency> |
There was a problem hiding this comment.
Cf. build.gradle.mustache.
jackson-datatype-jsr310 has been included directly in databind. This dependency does not exist anymore for jackson 3.
| @@ -299,8 +324,13 @@ | |||
| {{/swagger2AnnotationLibrary}} | |||
| <maven.compiler.source>11</maven.compiler.source> | |||
| <maven.compiler.target>11</maven.compiler.target> | |||
There was a problem hiding this comment.
Jackson 3 requires jdk17 or higher. Maybe we should increase this as well if useJackson3 ?
| sourceCompatibility = JavaVersion.VERSION_11 | ||
| targetCompatibility = JavaVersion.VERSION_11 |
There was a problem hiding this comment.
Same as pom.xml. Jackson 3 requires jdk17 or higher. Maybe we should increase this as well if useJackson3 ?
Add Jackson 3 support to java-native.
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 opt-in Jackson 3 support to the Java native client generator, enabling modern Jackson APIs while keeping Jackson 2 as the default. This adds a new flag, switches imports/config when enabled, and updates docs, tests, and samples.
New Features
Migration
Written for commit 8f7a982. Summary will update on new commits.