spring-boot: ElasticsearchClientAutoConfiguration causes global ObjectMapper to be overwritten
Tested with springboot 3.0.0
When the new ElasticsearchClient
is in the classpath, it triggers the ElasticsearchClientAutoConfiguration
which then overrides the application objectmapper / the one configured via Jackson2ObjectMapperBuilder
.
Reproducer for this issue; https://github.com/manofthepeace/spring3-elasticClient-mapperissue
Steps to reproduce;
- Run the test via
mvn test
the test will pass - modify the pom.xml and uncomment the elasticsearch-java dependency
- run the test via
mvn test
the test will fail - in
TestingWebApplication.java
use@SpringBootApplication(exclude = ElasticsearchClientAutoConfiguration.class)
- run the test via
mvn test
the test will pass
Expected behaviour;
the RestClientTransport
should use a new ObjectMapper, or somehow a user provided one, but not the one that spring-mvc / the global one is using. Can be done with new JacksonJsonpMapper()
or by passing an objectMapper to the JacksonJsonpMapper
constructor.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (10 by maintainers)
We think we should implement this in our auto-configuration. If a user wants a custom mapper they can override the
co.elastic.clients.json.jackson.JacksonJsonpMapper
bean (possibly using anyco.elastic.clients.json.JsonpMapper
implementation).A disadvantage of Elasticsearch no longer changing the configuration of the passed-in ObjectMapper is that setting
spring.jackson.serialization.indent-output
totrue
breaks bulk operations as the source for each document has to be on a single line.