Skip to content

Auto-configured JsonMapper backs off when any type of ObjectMapper is defined #47379

@Saljack

Description

@Saljack

I want to create a bean CsvMapper (or any other *Mapper), but if I create it then the autoconfigured default JsonMapper isn't created because there is @ConditionalOnMissingBean(ObjectMapper.class) and the CsvMapper extends ObjectMapper. This is problematic, and it can be unexpected behaviour. The only solution for this is to define a custom ObjectMapper with the same configuration as is in the autoconfiguration (copy paste code from the autoconfiguration).

If you change the condition to @ConditionalOnMissingBean(JsonMapper.class), then it is resolved and users can use multiple different *Mappers. The problem is that ObjectMapper is commonly used but if there is a new major version of Spring Boot 4 and if it uses the new version of Jackson 3, then it can be a good time to resolve it correctly.

See https://github.com/spring-projects/spring-boot/blob/main/module/spring-boot-jackson/src/main/java/org/springframework/boot/jackson/autoconfigure/JacksonAutoConfiguration.java#L114C28-L114C40

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions