From 078db8cb74a4c0d24f7b88bd048dedafec848faf Mon Sep 17 00:00:00 2001 From: Jonas Bergvall Date: Sat, 21 Jun 2014 23:56:59 +0200 Subject: [PATCH] Separate the configuration/creation of the default ObjectMapper bean from the registration of Jackson modules to avoid circular creation of the default ObjectMapper bean (and thus failing to obtain the ObjectMapper and registering the module(s)). Fixes gh-1132 --- .../jackson/JacksonAutoConfiguration.java | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java index d7905cf748..36d6086b1f 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java @@ -55,26 +55,11 @@ import com.fasterxml.jackson.datatype.jsr310.JSR310Module; */ @Configuration @ConditionalOnClass(ObjectMapper.class) -@EnableConfigurationProperties(HttpMapperProperties.class) public class JacksonAutoConfiguration { - @Autowired - private HttpMapperProperties properties = new HttpMapperProperties(); - @Autowired private ListableBeanFactory beanFactory; - @Bean - @Primary - @ConditionalOnMissingBean - public ObjectMapper jacksonObjectMapper() { - ObjectMapper objectMapper = new ObjectMapper(); - if (this.properties.isJsonSortKeys()) { - objectMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true); - } - return objectMapper; - } - @PostConstruct private void registerModulesWithObjectMappers() { Collection modules = getBeans(Module.class); @@ -88,6 +73,27 @@ public class JacksonAutoConfiguration { .values(); } + @Configuration + @ConditionalOnClass(ObjectMapper.class) + @EnableConfigurationProperties(HttpMapperProperties.class) + static class JacksonObjectMapperAutoConfiguration { + + @Autowired + private HttpMapperProperties properties = new HttpMapperProperties(); + + @Bean + @Primary + @ConditionalOnMissingBean + public ObjectMapper jacksonObjectMapper() { + ObjectMapper objectMapper = new ObjectMapper(); + if (this.properties.isJsonSortKeys()) { + objectMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true); + } + return objectMapper; + } + + } + @Configuration @ConditionalOnClass(JodaModule.class) static class JodaModuleAutoConfiguration {