Don't use global ObjectMapper when creating JacksonJsonpMapper

See gh-33438
Closes gh-33426
This commit is contained in:
Moritz Halbritter 2023-02-06 09:30:07 +01:00
parent cf60c1c8a2
commit 3af30b0a11
2 changed files with 15 additions and 4 deletions

View File

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

View File

@ -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.jackson.JacksonJsonpMapper;
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 @@ class ElasticsearchClientAutoConfigurationTests {
});
}
@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 {