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.

Signed-off-by: Pengfei-Lu <[email protected]>
  • Loading branch information
Pengfei-Lu committed Jun 30, 2023
1 parent 7d019c6 commit 33de51d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchClientConfigurations.ElasticsearchClientConfiguration;
import org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchClientConfigurations.ElasticsearchTransportConfiguration;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.autoconfigure.jsonb.JsonbAutoConfiguration;
import org.springframework.context.annotation.Import;

Expand All @@ -33,8 +32,7 @@
* @author Andy Wilkinson
* @since 3.0.0
*/
@AutoConfiguration(after = { JacksonAutoConfiguration.class, JsonbAutoConfiguration.class,
ElasticsearchRestClientAutoConfiguration.class })
@AutoConfiguration(after = { JsonbAutoConfiguration.class, ElasticsearchRestClientAutoConfiguration.class })
@ConditionalOnClass(ElasticsearchClient.class)
@Import({ ElasticsearchTransportConfiguration.class, ElasticsearchClientConfiguration.class })
public class ElasticsearchClientAutoConfiguration {
Expand Down
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 33de51d

Please sign in to comment.