Update Jackson customization docs to mention new builder customizer
Closes gh-6678
This commit is contained in:
parent
62867685ed
commit
9ba12f1ad9
|
@ -1184,10 +1184,11 @@ To get the server to render XML instead of JSON you might have to send an
|
|||
=== Customize the Jackson ObjectMapper
|
||||
Spring MVC (client and server side) uses `HttpMessageConverters` to negotiate content
|
||||
conversion in an HTTP exchange. If Jackson is on the classpath you already get the
|
||||
default converter(s) provided by `Jackson2ObjectMapperBuilder`.
|
||||
default converter(s) provided by `Jackson2ObjectMapperBuilder`, an instance of which
|
||||
is auto-configured for you.
|
||||
|
||||
The `ObjectMapper` (or `XmlMapper` for Jackson XML converter) instance created by default
|
||||
have the following customized properties:
|
||||
has the following customized properties:
|
||||
|
||||
* `MapperFeature.DEFAULT_VIEW_INCLUSION` is disabled
|
||||
* `DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES` is disabled
|
||||
|
@ -1226,19 +1227,26 @@ Note that, thanks to the use of <<boot-features-external-config-relaxed-binding,
|
|||
relaxed binding>>, the case of `indent_output` doesn't have to match the case of the
|
||||
corresponding enum constant which is `INDENT_OUTPUT`.
|
||||
|
||||
If you want to replace the default `ObjectMapper` completely, define a `@Bean` of that
|
||||
type and mark it as `@Primary`.
|
||||
This environment-based configuration is applied to the auto-configured
|
||||
`Jackson2ObjectMapperBuilder` bean, and will apply to any mappers created
|
||||
using the builder, including the auto-configured `ObjectMapper` bean.
|
||||
|
||||
Defining a `@Bean` of type `Jackson2ObjectMapperBuilder` will allow you to customize both
|
||||
default `ObjectMapper` and `XmlMapper` (used in `MappingJackson2HttpMessageConverter` and
|
||||
`MappingJackson2XmlHttpMessageConverter` respectively).
|
||||
The context's `Jackson2ObjectMapperBuilder` can be customized by one or more
|
||||
`Jackson2ObjectMapperBuilderCustomizer` beans. Such customizer beans can be ordered and
|
||||
Boot's own customizer has an order of 0, allowing additional customization to be applied
|
||||
both before and after Boot's customization.
|
||||
|
||||
Another way to customize Jackson is to add beans of type
|
||||
`com.fasterxml.jackson.databind.Module` to your context. They will be registered with every
|
||||
bean of type `ObjectMapper`, providing a global mechanism for contributing custom modules
|
||||
when you add new features to your application.
|
||||
Any beans of type `com.fasterxml.jackson.databind.Module` will be automatically registered
|
||||
with the auto-configured `Jackson2ObjectMapperBuilder` and applied to any `ObjectMapper`
|
||||
instances that it creates. This provides a global mechanism for contributing custom
|
||||
modules when you add new features to your application.
|
||||
|
||||
Finally, if you provide any `@Beans` of type `MappingJackson2HttpMessageConverter` then
|
||||
If you want to replace the default `ObjectMapper` completely, either define a `@Bean` of
|
||||
that type and mark it as `@Primary`, or, if you prefer the builder-based
|
||||
approachd, define a `Jackson2ObjectMapperBuilder` `@Bean`. Note that in either case this
|
||||
will disable all auto-configuration of the `ObjectMapper.
|
||||
|
||||
If you provide any `@Beans` of type `MappingJackson2HttpMessageConverter` then
|
||||
they will replace the default value in the MVC configuration. Also, a convenience bean is
|
||||
provided of type `HttpMessageConverters` (always available if you use the default MVC
|
||||
configuration) which has some useful methods to access the default and user-enhanced
|
||||
|
|
Loading…
Reference in New Issue