Skip to content

[Java] fix restclient with useJackson3 omitting default HttpMessageConverters (#24587) - #24640

Merged
wing328 merged 6 commits into
OpenAPITools:masterfrom
SubhamAshok:fix/24587-restclient-register-defaults
Aug 10, 2026
Merged

[Java] fix restclient with useJackson3 omitting default HttpMessageConverters (#24587)#24640
wing328 merged 6 commits into
OpenAPITools:masterfrom
SubhamAshok:fix/24587-restclient-register-defaults

Conversation

@SubhamAshok

@SubhamAshok SubhamAshok commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

PR checklist

  • Read the contribution guidelines.
  • Pull Request title cleanly describes the fix/feature.
  • Code compiles cleanly by running mvn clean install -DskipTests.
  • Added unit tests for the fix/feature.
  • Regenerated sample code via ./bin/generate-samples.sh ./bin/configs/java*.

Description of the Change

When generating the restclient library with useJackson3=true, ApiClient.mustache configures JacksonJsonHttpMessageConverter on HttpMessageConverters.ClientBuilder. I believe builder.registerDefaults() was accidentally omitted here. Without calling registerDefaults(), standard Spring converters (such as ByteArrayHttpMessageConverter, StringHttpMessageConverter, and ResourceHttpMessageConverter) are not registered on the built client.

Adding builder.registerDefaults() inside messageConverters ensures Spring's default converters remain registered alongside Jackson.

Fixes #24587

cc @bbdouglas @s2308 @Javier20 @wing328 @jpfinne


Summary by cubic

Fixes missing Spring default HttpMessageConverters in restclient when useJackson3=true by using builder.registerDefaults().withJsonConverter(...), and switches XML to withXmlConverter(...) to prevent duplicates. Restores ByteArray/String/Resource support and avoids duplicate converters. Fixes #24587.

  • Bug Fixes
    • Update ApiClient.mustache to call builder.registerDefaults().withJsonConverter(new JacksonJsonHttpMessageConverter(mapper)) and withXmlConverter(new JacksonXmlHttpMessageConverter(xmlMapper)); add a regression test; regenerate samples.
    • Bump spring-web to 7.0.8 across restclient/resttemplate templates and all Spring Boot 4 samples.

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

Review in cubic

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 4 files

Re-trigger cubic

{{#useJackson3}}
Consumer<HttpMessageConverters.ClientBuilder> messageConverters = builder -> {
builder.registerDefaults();
builder.addCustomConverter(new JacksonJsonHttpMessageConverter(mapper));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

shouldn't we use builder.registerDefaults().withJsonConverter(…)? Otherwise, it creates 2 json converters in the chain. Which technically works too, but it's unnecessary.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch on avoiding duplicate JSON converters. Since withJsonConverter requires Spring 7.0.7+ and pom.mustache currently defaults to 7.0.5, should we bump the template's Spring version to 7.0.8 and make the switch?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don't think bump is needed. the 7.0.7 requirement only applies without registerDefaults(). I think on 7.0.5: registerDefaults().withJsonConverter(…) gives the same 5 converters as a plain RestClient.builder()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Let me check and get back

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point. I updated it to use withJsonConverter.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

1 issue found across 5 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="samples/client/petstore/java/resttemplate-springBoot4-jackson3/pom.xml">

<violation number="1" location="samples/client/petstore/java/resttemplate-springBoot4-jackson3/pom.xml:272">
P3: The pom for this sample is bumped to Spring Web 7.0.8, but the Gradle build in the same generated sample still pins Spring Web 7.0.5 (build.gradle line 102, from build.gradle.mustache line 129 for useSpringBoot4). So the same templating options produce different Spring versions depending on build system, and the sample's pom and build.gradle now disagree with each other. If the intent of the 7.0.8 bump was the Spring 7.0.7+ withJsonConverter behavior, the Gradle path would silently stay on 7.0.5. Recommend bumping build.gradle.mustache (and regenerating the sample's build.gradle) to keep both in sync.</violation>
</file>

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<spring-web-version>7.0.5</spring-web-version>
<spring-web-version>7.0.8</spring-web-version>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P3: The pom for this sample is bumped to Spring Web 7.0.8, but the Gradle build in the same generated sample still pins Spring Web 7.0.5 (build.gradle line 102, from build.gradle.mustache line 129 for useSpringBoot4). So the same templating options produce different Spring versions depending on build system, and the sample's pom and build.gradle now disagree with each other. If the intent of the 7.0.8 bump was the Spring 7.0.7+ withJsonConverter behavior, the Gradle path would silently stay on 7.0.5. Recommend bumping build.gradle.mustache (and regenerating the sample's build.gradle) to keep both in sync.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/java/resttemplate-springBoot4-jackson3/pom.xml, line 272:

<comment>The pom for this sample is bumped to Spring Web 7.0.8, but the Gradle build in the same generated sample still pins Spring Web 7.0.5 (build.gradle line 102, from build.gradle.mustache line 129 for useSpringBoot4). So the same templating options produce different Spring versions depending on build system, and the sample's pom and build.gradle now disagree with each other. If the intent of the 7.0.8 bump was the Spring 7.0.7+ withJsonConverter behavior, the Gradle path would silently stay on 7.0.5. Recommend bumping build.gradle.mustache (and regenerating the sample's build.gradle) to keep both in sync.</comment>

<file context>
@@ -269,7 +269,7 @@
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 
-        <spring-web-version>7.0.5</spring-web-version>
+        <spring-web-version>7.0.8</spring-web-version>
         <jackson-version>3.1.5</jackson-version>
         <jakarta-annotation-version>3.0.0</jakarta-annotation-version>
</file context>

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

2 issues found across 8 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="samples/client/petstore/java/resttemplate-springBoot4-jackson3-jspecify/build.gradle">

<violation number="1" location="samples/client/petstore/java/resttemplate-springBoot4-jackson3-jspecify/build.gradle:102">
P2: Spring version now diverges within this regenerated sample: build.gradle was bumped to 7.0.8 but the sibling pom.xml still declares 7.0.5, so Maven and Gradle builds of the same sample use different Spring versions. Regenerate both build files from the template (which emits 7.0.8 for useSpringBoot4) to keep the sample in sync.</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:103">
P2: The sample regeneration for the Spring Boot 4 templates is incomplete, leaving three samples internally inconsistent: `build.gradle` now declares `spring_web_version = "7.0.8"` while the matching `pom.xml` in the same directory still pins `<spring-web-version>7.0.5`. This affects restclient-springBoot4-jackson2, resttemplate-springBoot4-jackson2, and resttemplate-springBoot4-jackson3-jspecify (the other three Spring Boot 4 samples bumped both files consistently). As generated artifacts, these samples should be reproducible from the templates (whose pom.mustache is already 7.0.8), so a Maven-based user of these samples would resolve Spring 7.0.5 while a Gradle user gets 7.0.8 — exactly the kind of sample drift this PR's commit intends to fix. Please regenerate these samples (or update the pom.xml to 7.0.8) so the Maven and Gradle artifacts match.</violation>
</file>

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

jackson_version = "3.1.5"
jackson_annotations_version = "2.21"
spring_web_version = "7.0.5"
spring_web_version = "7.0.8"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: Spring version now diverges within this regenerated sample: build.gradle was bumped to 7.0.8 but the sibling pom.xml still declares 7.0.5, so Maven and Gradle builds of the same sample use different Spring versions. Regenerate both build files from the template (which emits 7.0.8 for useSpringBoot4) to keep the sample in sync.

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

<comment>Spring version now diverges within this regenerated sample: build.gradle was bumped to 7.0.8 but the sibling pom.xml still declares 7.0.5, so Maven and Gradle builds of the same sample use different Spring versions. Regenerate both build files from the template (which emits 7.0.8 for useSpringBoot4) to keep the sample in sync.</comment>

<file context>
@@ -99,7 +99,7 @@ if(hasProperty('target') && target == 'android') {
     jackson_version = "3.1.5"
     jackson_annotations_version = "2.21"
-    spring_web_version = "7.0.5"
+    spring_web_version = "7.0.8"
     jakarta_annotation_version = "3.0.0"
     bean_validation_version = "3.1.1"
</file context>

jackson_annotations_version = "2.21"
jackson_databind_nullable_version = "0.2.11"
spring_web_version = "7.0.5"
spring_web_version = "7.0.8"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: The sample regeneration for the Spring Boot 4 templates is incomplete, leaving three samples internally inconsistent: build.gradle now declares spring_web_version = "7.0.8" while the matching pom.xml in the same directory still pins <spring-web-version>7.0.5. This affects restclient-springBoot4-jackson2, resttemplate-springBoot4-jackson2, and resttemplate-springBoot4-jackson3-jspecify (the other three Spring Boot 4 samples bumped both files consistently). As generated artifacts, these samples should be reproducible from the templates (whose pom.mustache is already 7.0.8), so a Maven-based user of these samples would resolve Spring 7.0.5 while a Gradle user gets 7.0.8 — exactly the kind of sample drift this PR's commit intends to fix. Please regenerate these samples (or update the pom.xml to 7.0.8) so the Maven and Gradle artifacts match.

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 103:

<comment>The sample regeneration for the Spring Boot 4 templates is incomplete, leaving three samples internally inconsistent: `build.gradle` now declares `spring_web_version = "7.0.8"` while the matching `pom.xml` in the same directory still pins `<spring-web-version>7.0.5`. This affects restclient-springBoot4-jackson2, resttemplate-springBoot4-jackson2, and resttemplate-springBoot4-jackson3-jspecify (the other three Spring Boot 4 samples bumped both files consistently). As generated artifacts, these samples should be reproducible from the templates (whose pom.mustache is already 7.0.8), so a Maven-based user of these samples would resolve Spring 7.0.5 while a Gradle user gets 7.0.8 — exactly the kind of sample drift this PR's commit intends to fix. Please regenerate these samples (or update the pom.xml to 7.0.8) so the Maven and Gradle artifacts match.</comment>

<file context>
@@ -100,7 +100,7 @@ ext {
     jackson_annotations_version = "2.21"
     jackson_databind_nullable_version = "0.2.11"
-    spring_web_version = "7.0.5"
+    spring_web_version = "7.0.8"
     jakarta_annotation_version = "3.0.0"
     bean_validation_version = "3.1.1"
</file context>

@SubhamAshok

Copy link
Copy Markdown
Contributor Author

@cubic-dev-ai Fixed. I regenerated the samples so the Spring versions match.

@cubic-dev-ai

cubic-dev-ai Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai Fixed. I regenerated the samples so the Spring versions match.

@SubhamAshok Looks right now. The key change is correct: chaining .withJsonConverter(...) on builder.registerDefaults() replaces the default JacksonJsonHttpMessageConverter in place instead of appending a second JSON converter, while keeping ByteArray/String/Resource defaults. That's exactly the intent of HttpMessageConverters.ClientBuilder in Spring 6/7.

The sample regeneration looks consistent too — spring_web_version bumped to 7.0.8 in the restclient and resttemplate templates (both build.gradle.mustache and pom.mustache), and every Spring Boot 4 sample follows, so no drift left behind. The regression test asserting the generated ApiClient.java contains builder.registerDefaults().withJsonConverter(...) is a good one — it guards the template output rather than just the test setup.

One small thing worth double-checking before merge: the withXml path still calls builder.addCustomConverter(new JacksonXmlHttpMessageConverter(xmlMapper)). Since the JSON converter is now being swapped via withJsonConverter, make sure the XML converter isn't being double-appended or fighting with the default when withXml=true and useJackson3=true are both on. If you can, add or point to a test with both flags enabled to confirm the combined behavior.

Tip: get faster answers by chatting with cubic’s review copilot in the review UI

…nverters (OpenAPITools#24587)

Call builder.registerDefaults() inside configureMessageConverters lambda when useJackson3 is enabled in restclient library, ensuring default converters (ByteArray, String, Resource) are registered alongside Jackson.

Fixes OpenAPITools#24587
…n3 (OpenAPITools#24587)

Chain withJsonConverter(JacksonJsonHttpMessageConverter) directly on builder.registerDefaults() to substitute the JSON converter in-place without adding a duplicate converter to the chain.
@SubhamAshok
SubhamAshok force-pushed the fix/24587-restclient-register-defaults branch from b54df91 to f8a8b87 Compare August 9, 2026 16:52
@SubhamAshok

Copy link
Copy Markdown
Contributor Author

@cubic-dev-ai Good catch! I updated the template to use withXmlConverter instead of addCustomConverter so it behaves consistently and avoids double-appending XML converters just like the JSON one. I verified the generated ApiClient.java compiles successfully locally. (Also rebased to fix the unrelated JSONTest SHA mismatch!)

@cubic-dev-ai

cubic-dev-ai Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai Good catch! I updated the template to use withXmlConverter instead of addCustomConverter so it behaves consistently and avoids double-appending XML converters just like the JSON one. I verified the generated ApiClient.java compiles successfully locally. (Also rebased to fix the unrelated JSONTest SHA mismatch!)

@SubhamAshok That change is right, and I verified the API to back it. Spring's HttpMessageConverters.Builder javadoc confirms withXmlConverter(HttpMessageConverter) "Overrides the default Jackson 3.x XML HttpMessageConverter" — same semantics as withJsonConverter, so you're overriding in place instead of appending. Since registerDefaults() is now chained on the same builder before both calls, the XML override also takes effect (the upstream discussion confirms manual overrides only apply once defaults are registered). No double-append, no fight with the default. Looks consistent and correct.

The rebase note about the unrelated JSONTest SHA mismatch makes sense too. I don't have any remaining concerns — this resolves the one open thread. Once CI is green, this is good to merge.

Tip: get faster answers by chatting with cubic’s review copilot in the review UI

@SubhamAshok

Copy link
Copy Markdown
Contributor Author

@anatoly-tamarack @wing328 All requested changes have been made (including using withXmlConverter to prevent double-appending) and all CI checks are green! Could you take another look when you have a moment?

@wing328 wing328 added this to the 7.25.0 milestone Aug 10, 2026
@wing328
wing328 merged commit fccb57d into OpenAPITools:master Aug 10, 2026
110 checks passed
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.

[BUG][JAVA][restclient] useJackson3: generated RestClient is missing Spring's default message converters (follow-up to #23354)

3 participants