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
pull/1132/merge
Jonas Bergvall 11 years ago committed by Dave Syer
parent 08ae390696
commit 078db8cb74

@ -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<Module> 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 {

Loading…
Cancel
Save