|
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 | 76 | import org.springframework.core.annotation.Order;
|
78 | 77 | import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
79 | 78 |
|
@@ -327,12 +326,13 @@ void moduleBeansAndWellKnownModulesAreRegisteredWithTheObjectMapperBuilder() {
|
327 | 326 | }
|
328 | 327 |
|
329 | 328 | @Test
|
330 |
| - void customModulesRegisteredByBuilderCustomizerWithHighestPrecedenceShouldBeRetained() { |
| 329 | + void customModulesRegisteredByBuilderCustomizerShouldBeRetained() { |
331 | 330 | this.contextRunner.withUserConfiguration(ModuleConfig.class, CustomModuleBuilderCustomizerConfig.class)
|
332 | 331 | .run((context) -> {
|
333 | 332 | ObjectMapper objectMapper = context.getBean(Jackson2ObjectMapperBuilder.class).build();
|
334 | 333 | assertThat(context.getBean(CustomModule.class).getOwners()).contains(objectMapper);
|
335 |
| - assertThat(objectMapper.getRegisteredModuleIds()).contains("customizer-module"); |
| 334 | + assertThat(objectMapper.getRegisteredModuleIds()).contains("module-A", "module-B", |
| 335 | + CustomModule.class.getName()); |
336 | 336 | });
|
337 | 337 | }
|
338 | 338 |
|
@@ -608,9 +608,15 @@ Jackson2ObjectMapperBuilderCustomizer customDateFormat() {
|
608 | 608 | static class CustomModuleBuilderCustomizerConfig {
|
609 | 609 |
|
610 | 610 | @Bean
|
611 |
| - @Order(Ordered.HIGHEST_PRECEDENCE) |
612 |
| - Jackson2ObjectMapperBuilderCustomizer customModuleCustomizer() { |
613 |
| - return (builder) -> builder.modulesToInstall(new SimpleModule("customizer-module")); |
| 611 | + @Order(-1) |
| 612 | + Jackson2ObjectMapperBuilderCustomizer highPrecedenceCustomizer() { |
| 613 | + return (builder) -> builder.modulesToInstall((modules) -> modules.add(new SimpleModule("module-A"))); |
| 614 | + } |
| 615 | + |
| 616 | + @Bean |
| 617 | + @Order(1) |
| 618 | + Jackson2ObjectMapperBuilderCustomizer lowPrecedenceCustomizer() { |
| 619 | + return (builder) -> builder.modulesToInstall((modules) -> modules.add(new SimpleModule("module-B"))); |
614 | 620 | }
|
615 | 621 |
|
616 | 622 | }
|
|
0 commit comments