spring-boot icon indicating copy to clipboard operation
spring-boot copied to clipboard

Use a separate ObjectMapper per technology

Open mhalbritter opened this issue 3 years ago • 2 comments

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.

mhalbritter avatar Dec 01 '22 16:12 mhalbritter

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();
	}
}

manofthepeace avatar Dec 01 '22 17:12 manofthepeace

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.

mhalbritter avatar Dec 02 '22 08:12 mhalbritter