From 1d9175706143a8458003a7b49de6306366ff8565 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 20 May 2024 15:54:12 +0100 Subject: [PATCH] Document that HttpMessageConverters can be used for reordering/removal Closes gh-40767 --- .../META-INF/additional-spring-configuration-metadata.json | 3 ++- .../spring-boot-docs/src/docs/asciidoc/web/servlet.adoc | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 97a85af2b384..cfa1a2545619 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -2069,7 +2069,8 @@ { "name": "spring.mvc.converters.preferred-json-mapper", "type": "java.lang.String", - "description": "Preferred JSON mapper to use for HTTP message conversion. By default, auto-detected according to the environment." + "defaultValue": "jackson", + "description": "Preferred JSON mapper to use for HTTP message conversion. By default, auto-detected according to the environment. Supported values are 'jackson', 'gson', and 'jsonb'. When other json mapping libraries (such as kotlinx.serialization) are present, use a custom HttpMessageConverters bean to control the preferred mapper." }, { "name": "spring.mvc.date-format", diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/web/servlet.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/web/servlet.adoc index 759afb22a087..cfa4c42ba3aa 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/web/servlet.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/web/servlet.adoc @@ -86,12 +86,15 @@ Sensible defaults are included out of the box. For example, objects can be automatically converted to JSON (by using the Jackson library) or XML (by using the Jackson XML extension, if available, or by using JAXB if the Jackson XML extension is not available). By default, strings are encoded in `UTF-8`. +Any `HttpMessageConverter` bean that is present in the context is added to the list of converters. +You can also override default converters in the same way. + If you need to add or customize converters, you can use Spring Boot's `HttpMessageConverters` class, as shown in the following listing: include::code:MyHttpMessageConvertersConfiguration[] -Any `HttpMessageConverter` bean that is present in the context is added to the list of converters. -You can also override default converters in the same way. +For further control, you can also sub-class `HttpMessageConverters` and override its `postProcessConverters` and/or `postProcessPartConverters` methods. +This can be useful when you want to re-order or remove some of the converters that Spring MVC configures by default.