spring-projects / spring-boot

Spring Boot
https://spring.io/projects/spring-boot
Apache License 2.0
74.48k stars 40.53k forks source link

Use a separate ObjectMapper per technology #33438

Open mhalbritter opened 1 year ago

mhalbritter commented 1 year ago

Currently we use a global ObjectMapper at least for WebMVC and for the Elasticsearch client (see https://github.com/spring-projects/spring-boot/issues/33426).

We should think about separating these ObjectMappers, because right now if you change for example the date time format for WebMVC, this changes also the serialization format used for ElasticSearch.

There may be other places which share the same object mapper.

manofthepeace commented 1 year ago

Since ObjectMapper is quite heavy, if at least there is a known way, per technology, to know how to override the ObjectMapper it could be nice. Like using the default, by default, but if needed have a sort of bean to override that default, like you have proposed for the elasticsearch case;

@Configuration(proxyBeanMethods = false)
class JacksonJsonpMapperConfiguration {
    @Bean
    JacksonJsonpMapper jacksonJsonpMapper() {
        return new JacksonJsonpMapper();
    }
}
mhalbritter commented 1 year ago

Yes, maybe we come to the conclusion that the drawbacks are not worth it and we stick to one ObjectMapper. In that case we should at least document the ramifications of that.