|
73 | 73 | import org.springframework.context.annotation.Configuration;
|
74 | 74 | import org.springframework.context.annotation.Import;
|
75 | 75 | import org.springframework.context.annotation.Primary;
|
| 76 | +import org.springframework.core.Ordered; |
| 77 | +import org.springframework.core.annotation.Order; |
76 | 78 | import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
77 | 79 |
|
78 | 80 | import static org.assertj.core.api.Assertions.assertThat;
|
@@ -324,6 +326,18 @@ void moduleBeansAndWellKnownModulesAreRegisteredWithTheObjectMapperBuilder() {
|
324 | 326 | });
|
325 | 327 | }
|
326 | 328 |
|
| 329 | + @Test |
| 330 | + void customModulesRegisteredByBuilderCustomizerWithHighestPrecedenceShouldBeRetained() { |
| 331 | + this.contextRunner.withUserConfiguration(ModuleConfig.class, ObjectMapperModuleBuilderCustomizerConfig.class) |
| 332 | + .run((context) -> { |
| 333 | + ObjectMapper objectMapper = context.getBean(Jackson2ObjectMapperBuilder.class).build(); |
| 334 | + assertThat(objectMapper.getRegisteredModuleIds()).contains("customizer-module"); |
| 335 | + assertThat(context.getBean(CustomModule.class).getOwners()).contains(objectMapper); |
| 336 | + assertThat(((DefaultSerializerProvider) objectMapper.getSerializerProviderInstance()) |
| 337 | + .hasSerializerFor(Baz.class, null)).isTrue(); |
| 338 | + }); |
| 339 | + } |
| 340 | + |
327 | 341 | @Test
|
328 | 342 | void defaultSerializationInclusion() {
|
329 | 343 | this.contextRunner.run((context) -> {
|
@@ -592,6 +606,17 @@ Jackson2ObjectMapperBuilderCustomizer customDateFormat() {
|
592 | 606 |
|
593 | 607 | }
|
594 | 608 |
|
| 609 | + @Configuration(proxyBeanMethods = false) |
| 610 | + static class ObjectMapperModuleBuilderCustomizerConfig { |
| 611 | + |
| 612 | + @Bean |
| 613 | + @Order(Ordered.HIGHEST_PRECEDENCE) |
| 614 | + Jackson2ObjectMapperBuilderCustomizer customModuleCustomizer() { |
| 615 | + return (builder) -> builder.modulesToInstall(new SimpleModule("customizer-module")); |
| 616 | + } |
| 617 | + |
| 618 | + } |
| 619 | + |
595 | 620 | @Configuration(proxyBeanMethods = false)
|
596 | 621 | static class ObjectMapperBuilderConsumerConfig {
|
597 | 622 |
|
|
0 commit comments