Skip to content

Commit

Permalink
fixes(java/restclient) Force usage of custom converter (#20112)
Browse files Browse the repository at this point in the history
* fixes(java/restclient) Force usage of custom converter

Insert custom converter at the beginning of the 'RestClientBuilder' converter list so as not to use default 'MappingJackson2HttpMessageConverter' 

Close #20111

* update samples

---------

Co-authored-by: William Cheng <[email protected]>
  • Loading branch information
antechrestos and wing328 authored Nov 19, 2024
1 parent 654f62c commit 18b01ca
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {

{{/withXml}}
Consumer<List<HttpMessageConverter<?>>> messageConverters = converters -> {
converters.add(new MappingJackson2HttpMessageConverter(mapper));
converters.add(0, new MappingJackson2HttpMessageConverter(mapper));
{{#withXml}}
converters.add(new MappingJackson2XmlHttpMessageConverter(xmlMapper));
converters.add(0, new MappingJackson2XmlHttpMessageConverter(xmlMapper));
{{/withXml}}
};

Expand Down Expand Up @@ -750,4 +750,4 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
return collectionFormat.collectionToString(values);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ protected void init() {
*/
public static RestClient.Builder buildRestClientBuilder(ObjectMapper mapper) {
Consumer<List<HttpMessageConverter<?>>> messageConverters = converters -> {
converters.add(new MappingJackson2HttpMessageConverter(mapper));
converters.add(0, new MappingJackson2HttpMessageConverter(mapper));
};

return RestClient.builder().messageConverters(messageConverters);
Expand Down Expand Up @@ -716,4 +716,4 @@ public String collectionPathParameterToString(CollectionFormat collectionFormat,

return collectionFormat.collectionToString(values);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected void init() {
*/
public static RestClient.Builder buildRestClientBuilder(ObjectMapper mapper) {
Consumer<List<HttpMessageConverter<?>>> messageConverters = converters -> {
converters.add(new MappingJackson2HttpMessageConverter(mapper));
converters.add(0, new MappingJackson2HttpMessageConverter(mapper));
};

return RestClient.builder().messageConverters(messageConverters);
Expand Down Expand Up @@ -714,4 +714,4 @@ public String collectionPathParameterToString(CollectionFormat collectionFormat,

return collectionFormat.collectionToString(values);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected void init() {
*/
public static RestClient.Builder buildRestClientBuilder(ObjectMapper mapper) {
Consumer<List<HttpMessageConverter<?>>> messageConverters = converters -> {
converters.add(new MappingJackson2HttpMessageConverter(mapper));
converters.add(0, new MappingJackson2HttpMessageConverter(mapper));
};

return RestClient.builder().messageConverters(messageConverters);
Expand Down Expand Up @@ -714,4 +714,4 @@ public String collectionPathParameterToString(CollectionFormat collectionFormat,

return collectionFormat.collectionToString(values);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ protected void init() {
*/
public static RestClient.Builder buildRestClientBuilder(ObjectMapper mapper) {
Consumer<List<HttpMessageConverter<?>>> messageConverters = converters -> {
converters.add(new MappingJackson2HttpMessageConverter(mapper));
converters.add(0, new MappingJackson2HttpMessageConverter(mapper));
};

return RestClient.builder().messageConverters(messageConverters);
Expand Down Expand Up @@ -734,4 +734,4 @@ public String collectionPathParameterToString(CollectionFormat collectionFormat,

return collectionFormat.collectionToString(values);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ protected void init() {
*/
public static RestClient.Builder buildRestClientBuilder(ObjectMapper mapper) {
Consumer<List<HttpMessageConverter<?>>> messageConverters = converters -> {
converters.add(new MappingJackson2HttpMessageConverter(mapper));
converters.add(0, new MappingJackson2HttpMessageConverter(mapper));
};

return RestClient.builder().messageConverters(messageConverters);
Expand Down Expand Up @@ -734,4 +734,4 @@ public String collectionPathParameterToString(CollectionFormat collectionFormat,

return collectionFormat.collectionToString(values);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ protected void init() {
*/
public static RestClient.Builder buildRestClientBuilder(ObjectMapper mapper) {
Consumer<List<HttpMessageConverter<?>>> messageConverters = converters -> {
converters.add(new MappingJackson2HttpMessageConverter(mapper));
converters.add(0, new MappingJackson2HttpMessageConverter(mapper));
};

return RestClient.builder().messageConverters(messageConverters);
Expand Down Expand Up @@ -734,4 +734,4 @@ public String collectionPathParameterToString(CollectionFormat collectionFormat,

return collectionFormat.collectionToString(values);
}
}
}

0 comments on commit 18b01ca

Please sign in to comment.