Skip to content

Commit

Permalink
Don't use global ObjectMapper when creating JacksonJsonpMapper
Browse files Browse the repository at this point in the history
See gh-33438
Closes gh-33426
  • Loading branch information
mhalbritter committed Feb 6, 2023
1 parent cf60c1c commit 3af30b0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -49,8 +49,8 @@ class ElasticsearchClientConfigurations {
static class JacksonJsonpMapperConfiguration {

@Bean
JacksonJsonpMapper jacksonJsonpMapper(ObjectMapper objectMapper) {
return new JacksonJsonpMapper(objectMapper);
JacksonJsonpMapper jacksonJsonpMapper() {
return new JacksonJsonpMapper();
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;

Expand Down Expand Up @@ -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 {

Expand Down

0 comments on commit 3af30b0

Please sign in to comment.