Commit 078db8cb authored by Jonas Bergvall's avatar Jonas Bergvall Committed by Dave Syer

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
parent 08ae3906
...@@ -55,26 +55,11 @@ import com.fasterxml.jackson.datatype.jsr310.JSR310Module; ...@@ -55,26 +55,11 @@ import com.fasterxml.jackson.datatype.jsr310.JSR310Module;
*/ */
@Configuration @Configuration
@ConditionalOnClass(ObjectMapper.class) @ConditionalOnClass(ObjectMapper.class)
@EnableConfigurationProperties(HttpMapperProperties.class)
public class JacksonAutoConfiguration { public class JacksonAutoConfiguration {
@Autowired
private HttpMapperProperties properties = new HttpMapperProperties();
@Autowired @Autowired
private ListableBeanFactory beanFactory; 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 @PostConstruct
private void registerModulesWithObjectMappers() { private void registerModulesWithObjectMappers() {
Collection<Module> modules = getBeans(Module.class); Collection<Module> modules = getBeans(Module.class);
...@@ -88,6 +73,27 @@ public class JacksonAutoConfiguration { ...@@ -88,6 +73,27 @@ public class JacksonAutoConfiguration {
.values(); .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 @Configuration
@ConditionalOnClass(JodaModule.class) @ConditionalOnClass(JodaModule.class)
static class JodaModuleAutoConfiguration { static class JodaModuleAutoConfiguration {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment