Skip to content

Commit 078db8c

Browse files
jonbe242Dave Syer
authored andcommitted
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
1 parent 08ae390 commit 078db8c

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration.java

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,11 @@
5555
*/
5656
@Configuration
5757
@ConditionalOnClass(ObjectMapper.class)
58-
@EnableConfigurationProperties(HttpMapperProperties.class)
5958
public class JacksonAutoConfiguration {
6059

61-
@Autowired
62-
private HttpMapperProperties properties = new HttpMapperProperties();
63-
6460
@Autowired
6561
private ListableBeanFactory beanFactory;
6662

67-
@Bean
68-
@Primary
69-
@ConditionalOnMissingBean
70-
public ObjectMapper jacksonObjectMapper() {
71-
ObjectMapper objectMapper = new ObjectMapper();
72-
if (this.properties.isJsonSortKeys()) {
73-
objectMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
74-
}
75-
return objectMapper;
76-
}
77-
7863
@PostConstruct
7964
private void registerModulesWithObjectMappers() {
8065
Collection<Module> modules = getBeans(Module.class);
@@ -88,6 +73,27 @@ private <T> Collection<T> getBeans(Class<T> type) {
8873
.values();
8974
}
9075

76+
@Configuration
77+
@ConditionalOnClass(ObjectMapper.class)
78+
@EnableConfigurationProperties(HttpMapperProperties.class)
79+
static class JacksonObjectMapperAutoConfiguration {
80+
81+
@Autowired
82+
private HttpMapperProperties properties = new HttpMapperProperties();
83+
84+
@Bean
85+
@Primary
86+
@ConditionalOnMissingBean
87+
public ObjectMapper jacksonObjectMapper() {
88+
ObjectMapper objectMapper = new ObjectMapper();
89+
if (this.properties.isJsonSortKeys()) {
90+
objectMapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
91+
}
92+
return objectMapper;
93+
}
94+
95+
}
96+
9197
@Configuration
9298
@ConditionalOnClass(JodaModule.class)
9399
static class JodaModuleAutoConfiguration {

0 commit comments

Comments
 (0)