Skip to content

Commit

Permalink
Auto-configured JacksonJsonpMapper is conditional on an ObjectMapper …
Browse files Browse the repository at this point in the history
…bean but does not use such a bean.
  • Loading branch information
Pengfei-Lu committed Jun 29, 2023
1 parent 7d019c6 commit 3b98ab4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 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 @@ -30,6 +30,7 @@
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.autoconfigure.jsonb.JsonbAutoConfiguration;
import org.springframework.boot.test.context.FilteredClassLoader;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -64,14 +65,16 @@ void withRestClientAutoConfigurationShouldDefineClientAndSupportingBeans() {

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

@Test
void withJsonbShouldDefineJsonbMapper() {
this.contextRunner.withConfiguration(AutoConfigurations.of(JsonbAutoConfiguration.class))
this.contextRunner.withClassLoader(new FilteredClassLoader(ObjectMapper.class))
.withConfiguration(AutoConfigurations.of(JsonbAutoConfiguration.class))
.withUserConfiguration(RestClientConfiguration.class)
.run((context) -> assertThat(context).hasSingleBean(JsonpMapper.class)
.hasSingleBean(JsonbJsonpMapper.class));
Expand Down

0 comments on commit 3b98ab4

Please sign in to comment.