Skip to content

Commit

Permalink
Fix JacksonJsonpMapper bean autoconfigure condition bug.
Browse files Browse the repository at this point in the history
Fix #36107.
  • Loading branch information
Pengfei-Lu committed Jun 29, 2023
1 parent 7d019c6 commit b94a80d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -44,7 +45,7 @@
class ElasticsearchClientConfigurations {

@ConditionalOnMissingBean(JsonpMapper.class)
@ConditionalOnBean(ObjectMapper.class)
@ConditionalOnClass(ObjectMapper.class)
@Configuration(proxyBeanMethods = false)
static class JacksonJsonpMapperConfiguration {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.json.JsonpMapper;
import co.elastic.clients.json.SimpleJsonpMapper;
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;
Expand Down Expand Up @@ -62,21 +60,6 @@ void withRestClientAutoConfigurationShouldDefineClientAndSupportingBeans() {
.hasSingleBean(ElasticsearchClient.class));
}

@Test
void withoutJsonbOrJacksonShouldDefineSimpleMapper() {
this.contextRunner.withUserConfiguration(RestClientConfiguration.class)
.run((context) -> assertThat(context).hasSingleBean(JsonpMapper.class)
.hasSingleBean(SimpleJsonpMapper.class));
}

@Test
void withJsonbShouldDefineJsonbMapper() {
this.contextRunner.withConfiguration(AutoConfigurations.of(JsonbAutoConfiguration.class))
.withUserConfiguration(RestClientConfiguration.class)
.run((context) -> assertThat(context).hasSingleBean(JsonpMapper.class)
.hasSingleBean(JsonbJsonpMapper.class));
}

@Test
void withJacksonShouldDefineJacksonMapper() {
this.contextRunner.withConfiguration(AutoConfigurations.of(JacksonAutoConfiguration.class))
Expand Down

0 comments on commit b94a80d

Please sign in to comment.