Skip to content

Commit 788fe61

Browse files
committed
Clarify why @primary is recommended when defining custom ObjectMapper
Closes gh-42598
1 parent 1020793 commit 788fe61

File tree

1 file changed

+2
-1
lines changed
  • spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto

1 file changed

+2
-1
lines changed

spring-boot-project/spring-boot-docs/src/docs/asciidoc/howto/spring-mvc.adoc

+2-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ Such customizer beans can be ordered (Boot's own customizer has an order of 0),
114114
Any beans of type `com.fasterxml.jackson.databind.Module` are automatically registered with the auto-configured `Jackson2ObjectMapperBuilder` and are applied to any `ObjectMapper` instances that it creates.
115115
This provides a global mechanism for contributing custom modules when you add new features to your application.
116116

117-
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 approach, define a `Jackson2ObjectMapperBuilder` `@Bean`.
117+
If you want to replace the default `ObjectMapper` completely, either define a `@Bean` of that type or, if you prefer the builder-based approach, define a `Jackson2ObjectMapperBuilder` `@Bean`.
118+
When defining an `ObjectMapper` bean, marking it as `@Primary` is recommended as the auto-configuration's `ObjectMapper` that it will replace is `@Primary`.
118119
Note that, in either case, doing so disables all auto-configuration of the `ObjectMapper`.
119120

120121
If you provide any `@Beans` of type `MappingJackson2HttpMessageConverter`, they replace the default value in the MVC configuration.

0 commit comments

Comments
 (0)