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;

  1. Run the test via mvn test the test will pass
  2. modify the pom.xml and uncomment the elasticsearch-java dependency
  3. run the test via mvn test the test will fail
  4. in TestingWebApplication.java use @SpringBootApplication(exclude = ElasticsearchClientAutoConfiguration.class)
  5. 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)

Most upvoted comments

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 any co.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 to true breaks bulk operations as the source for each document has to be on a single line.