Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -306,7 +306,7 @@ private Field findPropertyNamingStrategyField(String fieldName) {
}

private void configureModules(Jackson2ObjectMapperBuilder builder) {
builder.modulesToInstall(this.modules.toArray(new Module[0]));
builder.modulesToInstall((modules) -> modules.addAll(this.modules));
}

private void configureLocale(Jackson2ObjectMapperBuilder builder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -324,6 +326,16 @@ void moduleBeansAndWellKnownModulesAreRegisteredWithTheObjectMapperBuilder() {
});
}

@Test
void customModulesRegisteredByBuilderCustomizerWithHighestPrecedenceShouldBeRetained() {
this.contextRunner.withUserConfiguration(ModuleConfig.class, CustomModuleBuilderCustomizerConfig.class)
.run((context) -> {
ObjectMapper objectMapper = context.getBean(Jackson2ObjectMapperBuilder.class).build();
assertThat(context.getBean(CustomModule.class).getOwners()).contains(objectMapper);
assertThat(objectMapper.getRegisteredModuleIds()).contains("customizer-module");
});
}

@Test
void defaultSerializationInclusion() {
this.contextRunner.run((context) -> {
Expand Down Expand Up @@ -592,6 +604,17 @@ Jackson2ObjectMapperBuilderCustomizer customDateFormat() {

}

@Configuration(proxyBeanMethods = false)
static class CustomModuleBuilderCustomizerConfig {

@Bean
@Order(Ordered.HIGHEST_PRECEDENCE)
Jackson2ObjectMapperBuilderCustomizer customModuleCustomizer() {
return (builder) -> builder.modulesToInstall(new SimpleModule("customizer-module"));
}

}

@Configuration(proxyBeanMethods = false)
static class ObjectMapperBuilderConsumerConfig {

Expand Down