-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
[BUG][Java][RestClient][jackson3] restclient.messageConverters unset for ApiClient with default construction #23354
Copy link
Copy link
Open
Labels
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
- when constructing an ApiClient with the default constructor, the internal generated RestClient will not have any messageConverters set, resulting in errors like
Could not extract response: no suitable HttpMessageConverter found for response type [class ag.xyz.model.SomethingDto] and content type [application/json]
- with the pull request to support jackson3, logic for adding
JacksonJsonHttpMessageConverterto the rest client was added (which will be used, ifuseJackson3is true- https://github.com/OpenAPITools/openapi-generator/pull/23023/changes#top (see ApiClient.mustache)
- to achieve it, the method .withJsonConverter was used
- the build method DefaultHttpMessageConverters will only pick up the jsonConverter as part of
getCoreConverters(), if registerDefaults is set (by.registerDefaults())- https://github.com/spring-projects/spring-framework/blob/3be51b1c77617e2e199958ca4fc96fc82b4bd50b/spring-web/src/main/java/org/springframework/http/converter/DefaultHttpMessageConverters.java#L482
- the build method is called via initMessageConverters in
DefaultRestClientBuilder
openapi-generator version
- openapi-generator-maven-plugin 7.21.0
- spring framework 7.0.6
additional params used
<useSpringBoot4>true</useSpringBoot4>
<useJackson3>true</useJackson3>
<library>restclient</library>
<openApiNullable>false</openApiNullable>
<useJakartaEe>true</useJakartaEe>
<generateBuilders>true</generateBuilders>
<useSingleRequestParameter>static</useSingleRequestParameter>
<useAbstractionForFiles>true</useAbstractionForFiles>
Steps to reproduce
- create ApiClient with default constructor
- apiClient.restClient.messageConverters will be empty
this.apiClient = new ApiClient();- create ApiClient with construction like in mustache template
- apiClient.restClient.messageConverters will be empty
this.apiClient = new ApiClient(RestClient.builder()
.configureMessageConverters(c -> c
.withJsonConverter(new JacksonJsonHttpMessageConverter())
)
.build()
);- create ApiClient with construction like in mustache template, but use registerDefaults
- apiClient.restClient.messageConverters will have entries (5), including the JacksonJsonHttpMessageConverter
this.apiClient = new ApiClient(RestClient.builder()
.configureMessageConverters(c -> c
.registerDefaults()
.withJsonConverter(new JacksonJsonHttpMessageConverter())
)
.build()
);Related issues/PRs
- https://github.com/OpenAPITools/openapi-generator/pull/23023/changes#top (see ApiClient.mustache)
Suggest a fix
- adding
registerDefaults()beforehandwithJsonConverter(...)will lead to existing messageConverters, nevertheless I'm not too deep into it, to see the full consequences
Reactions are currently unavailable