Skip to content

Commit 241171f

Browse files
committed
Merge branch '2.1.x'
2 parents e80b6cf + 6cee5fe commit 241171f

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/gson/GsonAutoConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ public void customize(GsonBuilder builder) {
8484
.toCall(builder::generateNonExecutableJson);
8585
map.from(properties::getExcludeFieldsWithoutExposeAnnotation)
8686
.toCall(builder::excludeFieldsWithoutExposeAnnotation);
87-
map.from(properties::getSerializeNulls).toCall(builder::serializeNulls);
87+
map.from(properties::getSerializeNulls).whenTrue()
88+
.toCall(builder::serializeNulls);
8889
map.from(properties::getEnableComplexMapKeySerialization)
8990
.toCall(builder::enableComplexMapKeySerialization);
9091
map.from(properties::getDisableInnerClassSerialization)

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/gson/GsonAutoConfigurationTests.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,23 @@ public void excludeFieldsWithoutExposeAnnotation() {
8080
}
8181

8282
@Test
83-
public void serializeNulls() {
83+
public void serializeNullsTrue() {
8484
this.contextRunner.withPropertyValues("spring.gson.serialize-nulls:true")
8585
.run((context) -> {
8686
Gson gson = context.getBean(Gson.class);
8787
assertThat(gson.serializeNulls()).isTrue();
8888
});
8989
}
9090

91+
@Test
92+
public void serializeNullsFalse() {
93+
this.contextRunner.withPropertyValues("spring.gson.serialize-nulls:false")
94+
.run((context) -> {
95+
Gson gson = context.getBean(Gson.class);
96+
assertThat(gson.serializeNulls()).isFalse();
97+
});
98+
}
99+
91100
@Test
92101
public void enableComplexMapKeySerialization() {
93102
this.contextRunner

0 commit comments

Comments
 (0)