diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/gson/GsonAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/gson/GsonAutoConfiguration.java index 9bc3140a88..8714a78eb1 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/gson/GsonAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/gson/GsonAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -84,7 +84,8 @@ public class GsonAutoConfiguration { .toCall(builder::generateNonExecutableJson); map.from(properties::getExcludeFieldsWithoutExposeAnnotation) .toCall(builder::excludeFieldsWithoutExposeAnnotation); - map.from(properties::getSerializeNulls).toCall(builder::serializeNulls); + map.from(properties::getSerializeNulls).whenTrue() + .toCall(builder::serializeNulls); map.from(properties::getEnableComplexMapKeySerialization) .toCall(builder::enableComplexMapKeySerialization); map.from(properties::getDisableInnerClassSerialization) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/gson/GsonAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/gson/GsonAutoConfigurationTests.java index 37bdfe0c0f..982b9a1e3e 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/gson/GsonAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/gson/GsonAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2019 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. @@ -81,7 +81,7 @@ public class GsonAutoConfigurationTests { } @Test - public void serializeNulls() { + public void serializeNullsTrue() { this.contextRunner.withPropertyValues("spring.gson.serialize-nulls:true") .run((context) -> { Gson gson = context.getBean(Gson.class); @@ -89,6 +89,15 @@ public class GsonAutoConfigurationTests { }); } + @Test + public void serializeNullsFalse() { + this.contextRunner.withPropertyValues("spring.gson.serialize-nulls:false") + .run((context) -> { + Gson gson = context.getBean(Gson.class); + assertThat(gson.serializeNulls()).isFalse(); + }); + } + @Test public void enableComplexMapKeySerialization() { this.contextRunner