Skip to content

Commit e1d85b3

Browse files
committed
Apply default property inclusion to content
Previously, the setting was only applied to values. This worked for POJOs but had no effect on maps. Fixes gh-48343
1 parent e5928f7 commit e1d85b3

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.stream.Stream;
3030

3131
import com.fasterxml.jackson.annotation.JsonAutoDetect;
32+
import com.fasterxml.jackson.annotation.JsonInclude.Include;
3233
import com.fasterxml.jackson.annotation.PropertyAccessor;
3334
import org.jspecify.annotations.Nullable;
3435
import tools.jackson.databind.JacksonModule;
@@ -371,9 +372,10 @@ protected void customize(B builder) {
371372
if (this.jacksonProperties.isFindAndAddModules()) {
372373
builder.findAndAddModules(getClass().getClassLoader());
373374
}
374-
if (this.jacksonProperties.getDefaultPropertyInclusion() != null) {
375-
builder.changeDefaultPropertyInclusion(
376-
(handler) -> handler.withValueInclusion(this.jacksonProperties.getDefaultPropertyInclusion()));
375+
Include propertyInclusion = this.jacksonProperties.getDefaultPropertyInclusion();
376+
if (propertyInclusion != null) {
377+
builder.changeDefaultPropertyInclusion((handler) -> handler.withValueInclusion(propertyInclusion)
378+
.withContentInclusion(propertyInclusion));
377379
}
378380
if (this.jacksonProperties.getTimeZone() != null) {
379381
builder.defaultTimeZone(this.jacksonProperties.getTimeZone());

module/spring-boot-jackson/src/test/java/org/springframework/boot/jackson/autoconfigure/JacksonAutoConfigurationTests.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,19 +436,23 @@ void customModulesRegisteredByXmlMapperBuilderCustomizerShouldBeRetained() {
436436

437437
@EnumSource
438438
@ParameterizedTest
439-
void defaultSerializationInclusion(MapperType mapperType) {
439+
void defaultPropertyInclusion(MapperType mapperType) {
440440
this.contextRunner.run((context) -> {
441441
ObjectMapper mapper = mapperType.getMapper(context);
442+
assertThat(mapper.serializationConfig().getDefaultPropertyInclusion().getContentInclusion())
443+
.isEqualTo(JsonInclude.Include.USE_DEFAULTS);
442444
assertThat(mapper.serializationConfig().getDefaultPropertyInclusion().getValueInclusion())
443445
.isEqualTo(JsonInclude.Include.USE_DEFAULTS);
444446
});
445447
}
446448

447449
@EnumSource
448450
@ParameterizedTest
449-
void customSerializationInclusion(MapperType mapperType) {
451+
void customPropertyInclusion(MapperType mapperType) {
450452
this.contextRunner.withPropertyValues("spring.jackson.default-property-inclusion:non_null").run((context) -> {
451453
ObjectMapper mapper = mapperType.getMapper(context);
454+
assertThat(mapper.serializationConfig().getDefaultPropertyInclusion().getContentInclusion())
455+
.isEqualTo(JsonInclude.Include.NON_NULL);
452456
assertThat(mapper.serializationConfig().getDefaultPropertyInclusion().getValueInclusion())
453457
.isEqualTo(JsonInclude.Include.NON_NULL);
454458
});

0 commit comments

Comments
 (0)