mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-05-02 19:30:23 +01:00
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
This commit is contained in:
+5
-3
@@ -29,6 +29,7 @@ import java.util.function.BiConsumer;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
import tools.jackson.databind.JacksonModule;
|
||||
@@ -371,9 +372,10 @@ public final class JacksonAutoConfiguration {
|
||||
if (this.jacksonProperties.isFindAndAddModules()) {
|
||||
builder.findAndAddModules(getClass().getClassLoader());
|
||||
}
|
||||
if (this.jacksonProperties.getDefaultPropertyInclusion() != null) {
|
||||
builder.changeDefaultPropertyInclusion(
|
||||
(handler) -> handler.withValueInclusion(this.jacksonProperties.getDefaultPropertyInclusion()));
|
||||
Include propertyInclusion = this.jacksonProperties.getDefaultPropertyInclusion();
|
||||
if (propertyInclusion != null) {
|
||||
builder.changeDefaultPropertyInclusion((handler) -> handler.withValueInclusion(propertyInclusion)
|
||||
.withContentInclusion(propertyInclusion));
|
||||
}
|
||||
if (this.jacksonProperties.getTimeZone() != null) {
|
||||
builder.defaultTimeZone(this.jacksonProperties.getTimeZone());
|
||||
|
||||
+6
-2
@@ -436,9 +436,11 @@ class JacksonAutoConfigurationTests {
|
||||
|
||||
@EnumSource
|
||||
@ParameterizedTest
|
||||
void defaultSerializationInclusion(MapperType mapperType) {
|
||||
void defaultPropertyInclusion(MapperType mapperType) {
|
||||
this.contextRunner.run((context) -> {
|
||||
ObjectMapper mapper = mapperType.getMapper(context);
|
||||
assertThat(mapper.serializationConfig().getDefaultPropertyInclusion().getContentInclusion())
|
||||
.isEqualTo(JsonInclude.Include.USE_DEFAULTS);
|
||||
assertThat(mapper.serializationConfig().getDefaultPropertyInclusion().getValueInclusion())
|
||||
.isEqualTo(JsonInclude.Include.USE_DEFAULTS);
|
||||
});
|
||||
@@ -446,9 +448,11 @@ class JacksonAutoConfigurationTests {
|
||||
|
||||
@EnumSource
|
||||
@ParameterizedTest
|
||||
void customSerializationInclusion(MapperType mapperType) {
|
||||
void customPropertyInclusion(MapperType mapperType) {
|
||||
this.contextRunner.withPropertyValues("spring.jackson.default-property-inclusion:non_null").run((context) -> {
|
||||
ObjectMapper mapper = mapperType.getMapper(context);
|
||||
assertThat(mapper.serializationConfig().getDefaultPropertyInclusion().getContentInclusion())
|
||||
.isEqualTo(JsonInclude.Include.NON_NULL);
|
||||
assertThat(mapper.serializationConfig().getDefaultPropertyInclusion().getValueInclusion())
|
||||
.isEqualTo(JsonInclude.Include.NON_NULL);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user