feature(jackson3) add jackson3 support for Java Client generator - Restclient#23023
feature(jackson3) add jackson3 support for Java Client generator - Restclient#23023alex-nt wants to merge 12 commits intoOpenAPITools:masterfrom
Conversation
There was a problem hiding this comment.
4 issues found across 228 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 (all 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/restclient-spring-7/docs/PetApi.md">
<violation number="1" location="samples/client/petstore/java/restclient-spring-7/docs/PetApi.md:264">
P2: The example initializes a Set with Arrays.asList(), which returns a List and causes a compile-time type mismatch in the documentation sample.</violation>
</file>
<file name="modules/openapi-generator/src/main/resources/Java/libraries/restclient/ApiClient.mustache">
<violation number="1" location="modules/openapi-generator/src/main/resources/Java/libraries/restclient/ApiClient.mustache:188">
P2: Spring7 default JsonMapper omits JsonNullableModule registration, so generated clients using openApiNullable will not correctly serialize/deserialize JsonNullable fields.</violation>
</file>
<file name="samples/client/petstore/java/restclient-spring-7/docs/FakeApi.md">
<violation number="1" location="samples/client/petstore/java/restclient-spring-7/docs/FakeApi.md:1007">
P2: The example initializes a List<EnumClass> with `Arrays.asList(-efg)`, which is invalid Java syntax and will not compile. The documentation should use a valid EnumClass constant or factory method for the enum value.</violation>
</file>
<file name="samples/client/petstore/java/restclient-spring-7/.travis.yml">
<violation number="1" location="samples/client/petstore/java/restclient-spring-7/.travis.yml:8">
P2: Travis CI tests only JDK 8–12, but this sample requires Java 17 in build.gradle, so CI will fail to compile or test. Update the matrix to include Java 17+ and drop unsupported versions.</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.
| 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.
P2: The example initializes a Set with Arrays.asList(), which returns a List and causes a compile-time type mismatch in the documentation sample.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/java/restclient-spring-7/docs/PetApi.md, line 264:
<comment>The example initializes a Set with Arrays.asList(), which returns a List and causes a compile-time type mismatch in the documentation sample.</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>
| public static ObjectMapper createDefaultObjectMapper(@Nullable DateFormat dateFormat) { | ||
| {{#useSpring7}} | ||
| public static JsonMapper createDefaultMapper(@Nullable DateFormat dateFormat) { | ||
| return JsonMapper.builder() |
There was a problem hiding this comment.
P2: Spring7 default JsonMapper omits JsonNullableModule registration, so generated clients using openApiNullable will not correctly serialize/deserialize JsonNullable fields.
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/restclient/ApiClient.mustache, line 188:
<comment>Spring7 default JsonMapper omits JsonNullableModule registration, so generated clients using openApiNullable will not correctly serialize/deserialize JsonNullable fields.</comment>
<file context>
@@ -159,7 +183,21 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
- public static ObjectMapper createDefaultObjectMapper(@Nullable DateFormat dateFormat) {
+ {{#useSpring7}}
+ public static JsonMapper createDefaultMapper(@Nullable DateFormat dateFormat) {
+ return JsonMapper.builder()
+ .defaultDateFormat(dateFormat)
+ {{#failOnUnknownProperties}}
</file context>
| String enumQueryString = "_abc"; // String | Query parameter enum test (string) | ||
| Integer enumQueryInteger = 1; // Integer | Query parameter enum test (double) | ||
| Double enumQueryDouble = 1.1D; // Double | Query parameter enum test (double) | ||
| List<EnumClass> enumQueryModelArray = Arrays.asList(-efg); // List<EnumClass> | |
There was a problem hiding this comment.
P2: The example initializes a List with Arrays.asList(-efg), which is invalid Java syntax and will not compile. The documentation should use a valid EnumClass constant or factory method for the enum value.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/java/restclient-spring-7/docs/FakeApi.md, line 1007:
<comment>The example initializes a List<EnumClass> with `Arrays.asList(-efg)`, which is invalid Java syntax and will not compile. The documentation should use a valid EnumClass constant or factory method for the enum value.</comment>
<file context>
@@ -0,0 +1,1541 @@
+ String enumQueryString = "_abc"; // String | Query parameter enum test (string)
+ Integer enumQueryInteger = 1; // Integer | Query parameter enum test (double)
+ Double enumQueryDouble = 1.1D; // Double | Query parameter enum test (double)
+ List<EnumClass> enumQueryModelArray = Arrays.asList(-efg); // List<EnumClass> |
+ List<String> enumFormStringArray = Arrays.asList("$"); // List<String> | Form parameter enum test (string array)
+ String enumFormString = "_abc"; // String | Form parameter enum test (string)
</file context>
| # | ||
| language: java | ||
| jdk: | ||
| - openjdk12 |
There was a problem hiding this comment.
P2: Travis CI tests only JDK 8–12, but this sample requires Java 17 in build.gradle, so CI will fail to compile or test. Update the matrix to include Java 17+ and drop unsupported versions.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/java/restclient-spring-7/.travis.yml, line 8:
<comment>Travis CI tests only JDK 8–12, but this sample requires Java 17 in build.gradle, so CI will fail to compile or test. Update the matrix to include Java 17+ and drop unsupported versions.</comment>
<file context>
@@ -0,0 +1,22 @@
+#
+language: java
+jdk:
+ - openjdk12
+ - openjdk11
+ - openjdk10
</file context>
There was a problem hiding this comment.
It would be nice to standardize the name of the options with the Spring generator:
<useJackson3>true</useJackson3>
<useSpringBoot4>true</useSpringBoot4> >
There was a problem hiding this comment.
Done, I initially misread the spring docs 🙈.
|
Jackson3 also tries to deserialize using constructors. It might give regressions. See #22978 it can be fixed by adding |
There was a problem hiding this comment.
4 issues found across 433 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 (all 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/restclient-springBoot4-jackson2/docs/FakeApi.md">
<violation number="1" location="samples/client/petstore/java/restclient-springBoot4-jackson2/docs/FakeApi.md:1007">
P2: The example code uses `Arrays.asList(-efg)`, which is not a valid Java enum literal or identifier, so the sample will not compile.</violation>
</file>
<file name="samples/client/petstore/java/restclient-springBoot4-jackson2/docs/PetApi.md">
<violation number="1" location="samples/client/petstore/java/restclient-springBoot4-jackson2/docs/PetApi.md:264">
P2: The example initializes a Set with Arrays.asList(), which returns a List and won’t compile. The docs should construct a Set (e.g., new HashSet<>(Arrays.asList(...))) or use Set.of().</violation>
</file>
<file name="samples/client/petstore/java/restclient-springBoot4-jackson2/build.sbt">
<violation number="1" location="samples/client/petstore/java/restclient-springBoot4-jackson2/build.sbt:1">
P2: build.sbt is an empty TODO placeholder, leaving the SBT build for this sample non-functional.</violation>
</file>
<file name="modules/openapi-generator/src/main/resources/Java/libraries/restclient/ApiClient.mustache">
<violation number="1" location="modules/openapi-generator/src/main/resources/Java/libraries/restclient/ApiClient.mustache:187">
P2: Jackson 3 default mapper doesn’t register JsonNullableModule when openApiNullable is enabled, so JsonNullable fields won’t serialize/deserialize correctly in the default RestClient setup.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| String enumQueryString = "_abc"; // String | Query parameter enum test (string) | ||
| Integer enumQueryInteger = 1; // Integer | Query parameter enum test (double) | ||
| Double enumQueryDouble = 1.1D; // Double | Query parameter enum test (double) | ||
| List<EnumClass> enumQueryModelArray = Arrays.asList(-efg); // List<EnumClass> | |
There was a problem hiding this comment.
P2: The example code uses Arrays.asList(-efg), which is not a valid Java enum literal or identifier, so the sample will not compile.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/java/restclient-springBoot4-jackson2/docs/FakeApi.md, line 1007:
<comment>The example code uses `Arrays.asList(-efg)`, which is not a valid Java enum literal or identifier, so the sample will not compile.</comment>
<file context>
@@ -0,0 +1,1541 @@
+ String enumQueryString = "_abc"; // String | Query parameter enum test (string)
+ Integer enumQueryInteger = 1; // Integer | Query parameter enum test (double)
+ Double enumQueryDouble = 1.1D; // Double | Query parameter enum test (double)
+ List<EnumClass> enumQueryModelArray = Arrays.asList(-efg); // List<EnumClass> |
+ List<String> enumFormStringArray = Arrays.asList("$"); // List<String> | Form parameter enum test (string array)
+ String enumFormString = "_abc"; // String | Form parameter enum test (string)
</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.
P2: The example initializes a Set with Arrays.asList(), which returns a List and won’t compile. The docs should construct a Set (e.g., new HashSet<>(Arrays.asList(...))) or use Set.of().
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/java/restclient-springBoot4-jackson2/docs/PetApi.md, line 264:
<comment>The example initializes a Set with Arrays.asList(), which returns a List and won’t compile. The docs should construct a Set (e.g., new HashSet<>(Arrays.asList(...))) or use Set.of().</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>
| @@ -0,0 +1 @@ | |||
| # TODO | |||
There was a problem hiding this comment.
P2: build.sbt is an empty TODO placeholder, leaving the SBT build for this sample non-functional.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/java/restclient-springBoot4-jackson2/build.sbt, line 1:
<comment>build.sbt is an empty TODO placeholder, leaving the SBT build for this sample non-functional.</comment>
<file context>
@@ -0,0 +1 @@
+# TODO
</file context>
| public static ObjectMapper createDefaultObjectMapper(@Nullable DateFormat dateFormat) { | ||
| {{#useJackson3}} | ||
| public static JsonMapper createDefaultMapper(@Nullable DateFormat dateFormat) { | ||
| return JsonMapper.builder() |
There was a problem hiding this comment.
P2: Jackson 3 default mapper doesn’t register JsonNullableModule when openApiNullable is enabled, so JsonNullable fields won’t serialize/deserialize correctly in the default RestClient setup.
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/restclient/ApiClient.mustache, line 187:
<comment>Jackson 3 default mapper doesn’t register JsonNullableModule when openApiNullable is enabled, so JsonNullable fields won’t serialize/deserialize correctly in the default RestClient setup.</comment>
<file context>
@@ -159,7 +182,21 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
- public static ObjectMapper createDefaultObjectMapper(@Nullable DateFormat dateFormat) {
+ {{#useJackson3}}
+ public static JsonMapper createDefaultMapper(@Nullable DateFormat dateFormat) {
+ return JsonMapper.builder()
+ .defaultDateFormat(dateFormat)
+ {{#failOnUnknownProperties}}
</file context>
@jpfinne, this will work for |
Good question. Jackson3 tries to find a constructor for the deseralization. An all args constructor is used for sure. I would add |
There was a problem hiding this comment.
6 issues found across 650 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 (all 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/others/java/restclient-enum-in-multipart/src/main/java/org/openapitools/client/model/InlineObject.java">
<violation number="1" location="samples/client/others/java/restclient-enum-in-multipart/src/main/java/org/openapitools/client/model/InlineObject.java:41">
P2: @JsonIgnore on the only no‑args constructor makes Jackson ignore the sole creator, which can break deserialization for this model.</violation>
</file>
<file name="samples/client/echo_api/java/restclient/src/main/java/org/openapitools/client/model/Query.java">
<violation number="1" location="samples/client/echo_api/java/restclient/src/main/java/org/openapitools/client/model/Query.java:84">
P2: @JsonIgnore on the only no-args constructor prevents Jackson from treating it as a creator, leaving no usable constructor for deserialization of Query.</violation>
</file>
<file name="samples/client/echo_api/java/restclient/src/main/java/org/openapitools/client/model/DataQuery.java">
<violation number="1" location="samples/client/echo_api/java/restclient/src/main/java/org/openapitools/client/model/DataQuery.java:54">
P2: @JsonIgnore on the only no-arg constructor prevents Jackson from using it as a creator, leaving no constructor for deserialization and likely breaking JSON parsing for DataQuery.</violation>
</file>
<file name="samples/client/petstore/java/restclient-springBoot4-jackson2/.travis.yml">
<violation number="1" location="samples/client/petstore/java/restclient-springBoot4-jackson2/.travis.yml:8">
P2: Travis CI matrix omits JDK 17 even though the sample enforces Java 17 source/target compatibility, so CI builds on the listed JDKs will fail or not test the required baseline.</violation>
</file>
<file name="samples/client/petstore/java/restclient-springBoot4-jackson2/docs/FakeApi.md">
<violation number="1" location="samples/client/petstore/java/restclient-springBoot4-jackson2/docs/FakeApi.md:1007">
P2: The example uses `Arrays.asList(-efg)` which is not valid Java syntax for an enum value; it should reference the EnumClass constant (e.g., EnumClass._EFG).</violation>
</file>
<file name="samples/client/petstore/java/restclient-springBoot4-jackson2/build.gradle">
<violation number="1" location="samples/client/petstore/java/restclient-springBoot4-jackson2/build.gradle:35">
P2: Android build uses AGP 1.5 but sets Java 17 source/target; AGP 1.5 predates Java 8 support and won’t handle Java 17, so Android builds will fail when target=android is used.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
...a/restclient-enum-in-multipart/src/main/java/org/openapitools/client/model/InlineObject.java
Outdated
Show resolved
Hide resolved
samples/client/echo_api/java/restclient/src/main/java/org/openapitools/client/model/Query.java
Outdated
Show resolved
Hide resolved
...s/client/echo_api/java/restclient/src/main/java/org/openapitools/client/model/DataQuery.java
Outdated
Show resolved
Hide resolved
| # | ||
| language: java | ||
| jdk: | ||
| - openjdk12 |
There was a problem hiding this comment.
P2: Travis CI matrix omits JDK 17 even though the sample enforces Java 17 source/target compatibility, so CI builds on the listed JDKs will fail or not test the required baseline.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/java/restclient-springBoot4-jackson2/.travis.yml, line 8:
<comment>Travis CI matrix omits JDK 17 even though the sample enforces Java 17 source/target compatibility, so CI builds on the listed JDKs will fail or not test the required baseline.</comment>
<file context>
@@ -0,0 +1,22 @@
+#
+language: java
+jdk:
+ - openjdk12
+ - openjdk11
+ - openjdk10
</file context>
| String enumQueryString = "_abc"; // String | Query parameter enum test (string) | ||
| Integer enumQueryInteger = 1; // Integer | Query parameter enum test (double) | ||
| Double enumQueryDouble = 1.1D; // Double | Query parameter enum test (double) | ||
| List<EnumClass> enumQueryModelArray = Arrays.asList(-efg); // List<EnumClass> | |
There was a problem hiding this comment.
P2: The example uses Arrays.asList(-efg) which is not valid Java syntax for an enum value; it should reference the EnumClass constant (e.g., EnumClass._EFG).
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/java/restclient-springBoot4-jackson2/docs/FakeApi.md, line 1007:
<comment>The example uses `Arrays.asList(-efg)` which is not valid Java syntax for an enum value; it should reference the EnumClass constant (e.g., EnumClass._EFG).</comment>
<file context>
@@ -0,0 +1,1541 @@
+ String enumQueryString = "_abc"; // String | Query parameter enum test (string)
+ Integer enumQueryInteger = 1; // Integer | Query parameter enum test (double)
+ Double enumQueryDouble = 1.1D; // Double | Query parameter enum test (double)
+ List<EnumClass> enumQueryModelArray = Arrays.asList(-efg); // List<EnumClass> |
+ List<String> enumFormStringArray = Arrays.asList("$"); // List<String> | Form parameter enum test (string array)
+ String enumFormString = "_abc"; // String | Form parameter enum test (string)
</file context>
| targetSdkVersion 22 | ||
| } | ||
| compileOptions { | ||
| sourceCompatibility JavaVersion.VERSION_17 |
There was a problem hiding this comment.
P2: Android build uses AGP 1.5 but sets Java 17 source/target; AGP 1.5 predates Java 8 support and won’t handle Java 17, so Android builds will fail when target=android is used.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/java/restclient-springBoot4-jackson2/build.gradle, line 35:
<comment>Android build uses AGP 1.5 but sets Java 17 source/target; AGP 1.5 predates Java 8 support and won’t handle Java 17, so Android builds will fail when target=android is used.</comment>
<file context>
@@ -0,0 +1,136 @@
+ targetSdkVersion 22
+ }
+ compileOptions {
+ sourceCompatibility JavaVersion.VERSION_17
+ targetCompatibility JavaVersion.VERSION_17
+ }
</file context>
@alex-nt Forget about So the java generator is better that the spring generator ! |
|
@jpfinne done, I reverted to what was there before. I think now it should be ok? |
My third thought: For example, the restclient generation with all arg constructors gives The all arg constructor is used by jackson3 to deserialize. Jackson2 uses the setters. |
|
@jpfinne I checked the generated files and cannot see where it is generated with default value. You mention the following: But I see it generated as: What else do I need to enable in order to get also default (non-null) values? By adding |
Add option to generate
Restclientusing latest spring 7.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)fixes #22985Summary by cubic
Adds Spring Boot 4 / Spring Framework 7 support to the Java RestClient generator with an optional Jackson 3 path. Updates templates, converters, and samples on a Java 17 baseline.
New Features
Migration
Written for commit 1b3aefc. Summary will update on new commits.