From 10ae5e8f3f2f15cd5fb39cdcea0482219dfd8b13 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 14 Mar 2017 19:03:49 +0000 Subject: [PATCH] Upgrade to Jackson 2.9.0.pr1 As part of the upgrade, this commit removes the use of any API that has been deprecated in 2.9.0.pr1. This includes the config props endpoint's use of SerializationFeature.WRITE_NULL_MAP_VALUES. This has been replaced with configuring serialization inclusion to only include properties with non-null values. This means that all null-valued properties will no longer be serialized, not just those that are an entry in a map. Closes gh-8604 Closes gh-8537 --- ...ConfigurationPropertiesReportEndpoint.java | 3 ++- ...gurationPropertiesReportEndpointTests.java | 22 +++++++++++++++++++ .../JacksonAutoConfigurationTests.java | 14 +++++++----- spring-boot-dependencies/pom.xml | 2 +- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpoint.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpoint.java index 3558d565da..4528546a67 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpoint.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpoint.java @@ -22,6 +22,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.databind.BeanDescription; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationConfig; @@ -171,7 +172,7 @@ public class ConfigurationPropertiesReportEndpoint */ protected void configureObjectMapper(ObjectMapper mapper) { mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); - mapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false); + mapper.setSerializationInclusion(Include.NON_NULL); applyCglibFilters(mapper); applySerializationModifier(mapper); } diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpointTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpointTests.java index 3c124362a4..db9e820621 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpointTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/ConfigurationPropertiesReportEndpointTests.java @@ -61,6 +61,18 @@ public class ConfigurationPropertiesReportEndpointTests assertThat(nestedProperties).isNotNull(); assertThat(nestedProperties.get("prefix")).isEqualTo("test"); assertThat(nestedProperties.get("properties")).isNotNull(); + + } + + @Test + @SuppressWarnings("unchecked") + public void entriesWithNullValuesAreNotIncluded() { + ConfigurationPropertiesReportEndpoint report = getEndpointBean(); + Map properties = report.invoke(); + Map nestedProperties = (Map) properties + .get("testProperties"); + assertThat((Map) nestedProperties.get("properties")) + .doesNotContainKey("nullValue"); } @Test @@ -274,6 +286,8 @@ public class ConfigurationPropertiesReportEndpointTests private List> listOfListItems = new ArrayList<>(); + private String nullValue = null; + public TestProperties() { this.secrets.put("mine", "myPrivateThing"); this.secrets.put("yours", "yourPrivateThing"); @@ -337,6 +351,14 @@ public class ConfigurationPropertiesReportEndpointTests this.listOfListItems = listOfListItems; } + public String getNullValue() { + return this.nullValue; + } + + public void setNullValue(String nullValue) { + this.nullValue = nullValue; + } + public static class Hidden { private String mine = "mySecret"; diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfigurationTests.java index 94bc795ef1..2d695efdf5 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jackson/JacksonAutoConfigurationTests.java @@ -30,6 +30,8 @@ import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.ObjectCodec; +import com.fasterxml.jackson.databind.AnnotationIntrospector; +import com.fasterxml.jackson.databind.DeserializationConfig; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.MapperFeature; @@ -38,7 +40,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.SerializerProvider; -import com.fasterxml.jackson.databind.introspect.Annotated; import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.databind.util.StdDateFormat; import com.fasterxml.jackson.module.paramnames.ParameterNamesModule; @@ -59,6 +60,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Primary; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; +import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -445,10 +447,12 @@ public class JacksonAutoConfigurationTests { Class... configClasses) { this.context.register(configClasses); this.context.refresh(); - Annotated annotated = mock(Annotated.class); - Mode mode = this.context.getBean(ObjectMapper.class).getDeserializationConfig() - .getAnnotationIntrospector().findCreatorBinding(annotated); - assertThat(mode).isEqualTo(expectedMode); + DeserializationConfig deserializationConfig = this.context + .getBean(ObjectMapper.class).getDeserializationConfig(); + AnnotationIntrospector annotationIntrospector = deserializationConfig + .getAnnotationIntrospector().allIntrospectors().iterator().next(); + assertThat(ReflectionTestUtils.getField(annotationIntrospector, "creatorBinding")) + .isEqualTo(expectedMode); } public static class MyDateFormat extends SimpleDateFormat { diff --git a/spring-boot-dependencies/pom.xml b/spring-boot-dependencies/pom.xml index 244ed91c68..7812a213fa 100644 --- a/spring-boot-dependencies/pom.xml +++ b/spring-boot-dependencies/pom.xml @@ -94,7 +94,7 @@ 4.5.3 4.4.6 8.2.6.Final - 2.8.7 + 2.9.0.pr1 2.7.8 3.21.0-GA 1.0.0