|
3 | 3 |
|
4 | 4 | [.small]#xref:web/webflux/config.adoc#webflux-config-message-codecs[See equivalent in the Reactive stack]#
|
5 | 5 |
|
6 |
| -You can set the `HttpMessageConverter` instances to use in Java configuration, |
7 |
| -replacing the ones used by default, by overriding |
8 |
| -{spring-framework-api}/web/servlet/config/annotation/WebMvcConfigurer.html#configureMessageConverters-java.util.List-[`configureMessageConverters()`]. |
9 |
| -You can also customize the list of configured message converters at the end by overriding |
10 |
| -{spring-framework-api}/web/servlet/config/annotation/WebMvcConfigurer.html#extendMessageConverters-java.util.List-[`extendMessageConverters()`]. |
| 6 | +You can configure the `HttpMessageConverter` instances to use by overriding |
| 7 | +{spring-framework-api}/web/servlet/config/annotation/WebMvcConfigurer.html#configureMessageConverters(org.springframework.http.converter.HttpMessageConverters.Builder)[`configureMessageConverters()`]. |
11 | 8 |
|
12 |
| -TIP: In a Spring Boot application, the `WebMvcAutoConfiguration` adds any |
13 |
| -`HttpMessageConverter` beans it detects, in addition to default converters. Hence, in a |
14 |
| -Boot application, prefer to use the {spring-boot-docs-ref}/web/servlet.html#web.servlet.spring-mvc.message-converters[HttpMessageConverters] |
15 |
| -mechanism. Or alternatively, use `extendMessageConverters` to modify message converters |
16 |
| -at the end. |
17 |
| - |
18 |
| -The following example adds XML and Jackson JSON converters with a customized `ObjectMapper` |
19 |
| -instead of the default ones: |
| 9 | +The following example configures custom Jackson JSON and XML converters with customized mappers instead of the default |
| 10 | +ones: |
20 | 11 |
|
21 | 12 | include-code::./WebConfiguration[tag=snippet,indent=0]
|
22 |
| - |
23 |
| -In the preceding example, |
24 |
| -{spring-framework-api}/http/converter/json/Jackson2ObjectMapperBuilder.html[`Jackson2ObjectMapperBuilder`] |
25 |
| -is used to create a common configuration for both `MappingJackson2HttpMessageConverter` and |
26 |
| -`MappingJackson2XmlHttpMessageConverter` with indentation enabled, a customized date format, |
27 |
| -and the registration of |
28 |
| -{jackson-github-org}/jackson-module-parameter-names[`jackson-module-parameter-names`], |
29 |
| -Which adds support for accessing parameter names (a feature added in Java 8). |
30 |
| - |
31 |
| -This builder customizes Jackson's default properties as follows: |
32 |
| - |
33 |
| -* {jackson-docs}/jackson-databind/javadoc/2.6/com/fasterxml/jackson/databind/DeserializationFeature.html#FAIL_ON_UNKNOWN_PROPERTIES[`DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES`] is disabled. |
34 |
| -* {jackson-docs}/jackson-databind/javadoc/2.6/com/fasterxml/jackson/databind/MapperFeature.html#DEFAULT_VIEW_INCLUSION[`MapperFeature.DEFAULT_VIEW_INCLUSION`] is disabled. |
35 |
| - |
36 |
| -It also automatically registers the following well-known modules if they are detected on the classpath: |
37 |
| - |
38 |
| -* {jackson-github-org}/jackson-datatype-jsr310[jackson-datatype-jsr310]: Support for Java 8 Date and Time API types. |
39 |
| -* {jackson-github-org}/jackson-datatype-jdk8[jackson-datatype-jdk8]: Support for other Java 8 types, such as `Optional`. |
40 |
| -* {jackson-github-org}/jackson-module-kotlin[jackson-module-kotlin]: Support for Kotlin classes and data classes. |
41 |
| - |
42 |
| -NOTE: Enabling indentation with Jackson XML support requires |
43 |
| -https://search.maven.org/#search%7Cgav%7C1%7Cg%3A%22org.codehaus.woodstox%22%20AND%20a%3A%22woodstox-core-asl%22[`woodstox-core-asl`] |
44 |
| -dependency in addition to https://search.maven.org/#search%7Cga%7C1%7Ca%3A%22jackson-dataformat-xml%22[`jackson-dataformat-xml`] one. |
45 |
| - |
46 |
| -Other interesting Jackson modules are available: |
47 |
| - |
48 |
| -* https://github.com/zalando/jackson-datatype-money[jackson-datatype-money]: Support for `javax.money` types (unofficial module). |
49 |
| -* {jackson-github-org}/jackson-datatype-hibernate[jackson-datatype-hibernate]: Support for Hibernate-specific types and properties (including lazy-loading aspects). |
0 commit comments