From 3af30b0a114be586e3cdfa0d49d5c5385753c511 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Mon, 6 Feb 2023 09:30:07 +0100 Subject: [PATCH] Don't use global ObjectMapper when creating JacksonJsonpMapper See gh-33438 Closes gh-33426 --- .../ElasticsearchClientConfigurations.java | 6 +++--- .../ElasticsearchClientAutoConfigurationTests.java | 13 ++++++++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchClientConfigurations.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchClientConfigurations.java index 19569fb00117..008ea9dd27bc 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchClientConfigurations.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchClientConfigurations.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,8 +49,8 @@ class ElasticsearchClientConfigurations { static class JacksonJsonpMapperConfiguration { @Bean - JacksonJsonpMapper jacksonJsonpMapper(ObjectMapper objectMapper) { - return new JacksonJsonpMapper(objectMapper); + JacksonJsonpMapper jacksonJsonpMapper() { + return new JacksonJsonpMapper(); } } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchClientAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchClientAutoConfigurationTests.java index 421e966fe2b0..fee56198b496 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchClientAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchClientAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ import co.elastic.clients.json.jsonb.JsonbJsonpMapper; import co.elastic.clients.transport.ElasticsearchTransport; import co.elastic.clients.transport.rest_client.RestClientTransport; +import com.fasterxml.jackson.databind.ObjectMapper; import org.elasticsearch.client.RestClient; import org.junit.jupiter.api.Test; @@ -108,6 +109,16 @@ void withCustomTransportClientShouldUseIt() { }); } + @Test + void jacksonJsonpMapperDoesNotUseGlobalObjectMapper() { + this.contextRunner.withConfiguration(AutoConfigurations.of(JacksonAutoConfiguration.class)) + .withUserConfiguration(RestClientConfiguration.class).run((context) -> { + ObjectMapper objectMapper = context.getBean(ObjectMapper.class); + JacksonJsonpMapper jacksonJsonpMapper = context.getBean(JacksonJsonpMapper.class); + assertThat(jacksonJsonpMapper.objectMapper()).isNotSameAs(objectMapper); + }); + } + @Configuration(proxyBeanMethods = false) static class RestClientConfiguration {