|
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,16 @@ void moduleBeansAndWellKnownModulesAreRegisteredWithTheObjectMapperBuilder() {
|
324 | 326 | });
|
325 | 327 | }
|
326 | 328 |
|
| 329 | + @Test |
| 330 | + void customModulesRegisteredByBuilderCustomizerWithHighestPrecedenceShouldBeRetained() { |
| 331 | + this.contextRunner.withUserConfiguration(ModuleConfig.class, CustomModuleBuilderCustomizerConfig.class) |
| 332 | + .run((context) -> { |
| 333 | + ObjectMapper objectMapper = context.getBean(Jackson2ObjectMapperBuilder.class).build(); |
| 334 | + assertThat(context.getBean(CustomModule.class).getOwners()).contains(objectMapper); |
| 335 | + assertThat(objectMapper.getRegisteredModuleIds()).contains("customizer-module"); |
| 336 | + }); |
| 337 | + } |
| 338 | + |
327 | 339 | @Test
|
328 | 340 | void defaultSerializationInclusion() {
|
329 | 341 | this.contextRunner.run((context) -> {
|
@@ -592,6 +604,17 @@ Jackson2ObjectMapperBuilderCustomizer customDateFormat() {
|
592 | 604 |
|
593 | 605 | }
|
594 | 606 |
|
| 607 | + @Configuration(proxyBeanMethods = false) |
| 608 | + static class CustomModuleBuilderCustomizerConfig { |
| 609 | + |
| 610 | + @Bean |
| 611 | + @Order(Ordered.HIGHEST_PRECEDENCE) |
| 612 | + Jackson2ObjectMapperBuilderCustomizer customModuleCustomizer() { |
| 613 | + return (builder) -> builder.modulesToInstall(new SimpleModule("customizer-module")); |
| 614 | + } |
| 615 | + |
| 616 | + } |
| 617 | + |
595 | 618 | @Configuration(proxyBeanMethods = false)
|
596 | 619 | static class ObjectMapperBuilderConsumerConfig {
|
597 | 620 |
|
|
0 commit comments