Upgrade to Jackson 2.9.0.pr2

As part of the upgrade, this commit removes the use of any API that
has been deprecated in 2.9. 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
Closes gh-7695
pull/8132/merge
Andy Wilkinson 8 years ago
parent 3024ed8316
commit 87ebec6838

@ -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);
}

@ -150,8 +150,8 @@ public class ConfigurationPropertiesReportEndpointSerializationTests {
Map<String, Object> map = (Map<String, Object>) nestedProperties
.get("properties");
assertThat(map).isNotNull();
assertThat(map).hasSize(3);
assertThat((map.get("map"))).isNull();
assertThat(map).hasSize(2);
assertThat(map).doesNotContainKey("map");
}
@Test

@ -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<String, Object> properties = report.invoke();
Map<String, Object> nestedProperties = (Map<String, Object>) properties
.get("testProperties");
assertThat((Map<String, Object>) nestedProperties.get("properties"))
.doesNotContainKey("nullValue");
}
@Test
@ -274,6 +286,8 @@ public class ConfigurationPropertiesReportEndpointTests
private List<List<ListItem>> 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";

@ -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 {

@ -95,7 +95,7 @@
<httpclient.version>4.5.3</httpclient.version>
<httpcore.version>4.4.6</httpcore.version>
<infinispan.version>8.2.6.Final</infinispan.version>
<jackson.version>2.8.7</jackson.version>
<jackson.version>2.9.0.pr2</jackson.version>
<janino.version>2.7.8</janino.version>
<javassist.version>3.21.0-GA</javassist.version> <!-- Same as Hibernate -->
<javax-cache.version>1.0.0</javax-cache.version>

Loading…
Cancel
Save