Skip to content

Commit 3af30b0

Browse files
committed
Don't use global ObjectMapper when creating JacksonJsonpMapper
See gh-33438 Closes gh-33426
1 parent cf60c1c commit 3af30b0

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchClientConfigurations.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -49,8 +49,8 @@ class ElasticsearchClientConfigurations {
4949
static class JacksonJsonpMapperConfiguration {
5050

5151
@Bean
52-
JacksonJsonpMapper jacksonJsonpMapper(ObjectMapper objectMapper) {
53-
return new JacksonJsonpMapper(objectMapper);
52+
JacksonJsonpMapper jacksonJsonpMapper() {
53+
return new JacksonJsonpMapper();
5454
}
5555

5656
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchClientAutoConfigurationTests.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@
2323
import co.elastic.clients.json.jsonb.JsonbJsonpMapper;
2424
import co.elastic.clients.transport.ElasticsearchTransport;
2525
import co.elastic.clients.transport.rest_client.RestClientTransport;
26+
import com.fasterxml.jackson.databind.ObjectMapper;
2627
import org.elasticsearch.client.RestClient;
2728
import org.junit.jupiter.api.Test;
2829

@@ -108,6 +109,16 @@ void withCustomTransportClientShouldUseIt() {
108109
});
109110
}
110111

112+
@Test
113+
void jacksonJsonpMapperDoesNotUseGlobalObjectMapper() {
114+
this.contextRunner.withConfiguration(AutoConfigurations.of(JacksonAutoConfiguration.class))
115+
.withUserConfiguration(RestClientConfiguration.class).run((context) -> {
116+
ObjectMapper objectMapper = context.getBean(ObjectMapper.class);
117+
JacksonJsonpMapper jacksonJsonpMapper = context.getBean(JacksonJsonpMapper.class);
118+
assertThat(jacksonJsonpMapper.objectMapper()).isNotSameAs(objectMapper);
119+
});
120+
}
121+
111122
@Configuration(proxyBeanMethods = false)
112123
static class RestClientConfiguration {
113124

0 commit comments

Comments
 (0)