Upgrade to Jackson 2.7.2

Closes gh-5081
This commit is contained in:
Andy Wilkinson
2016-03-01 16:37:51 +00:00
parent 355860fd09
commit ef5087c5ee
8 changed files with 83 additions and 29 deletions

View File

@@ -166,9 +166,9 @@ public class JacksonAutoConfiguration {
public Jackson2ObjectMapperBuilder jacksonObjectMapperBuilder() {
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
builder.applicationContext(this.applicationContext);
if (this.jacksonProperties.getSerializationInclusion() != null) {
if (this.jacksonProperties.getDefaultPropertyInclusion() != null) {
builder.serializationInclusion(
this.jacksonProperties.getSerializationInclusion());
this.jacksonProperties.getDefaultPropertyInclusion());
}
if (this.jacksonProperties.getTimeZone() != null) {
builder.timeZone(this.jacksonProperties.getTimeZone());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2015 the original author or authors.
* Copyright 2012-2016 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.
@@ -29,6 +29,7 @@ import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
/**
* Configuration properties to configure Jackson.
@@ -89,7 +90,7 @@ public class JacksonProperties {
* Controls the inclusion of properties during serialization. Configured with one of
* the values in Jackson's JsonInclude.Include enumeration.
*/
private JsonInclude.Include serializationInclusion;
private JsonInclude.Include defaultPropertyInclusion;
/**
* Time zone used when formatting dates. Configured using any recognized time zone
@@ -146,12 +147,24 @@ public class JacksonProperties {
return this.generator;
}
@Deprecated
@DeprecatedConfigurationProperty(reason = "ObjectMapper.setSerializationInclusion was deprecated in Jackson 2.7", replacement = "spring.jackson.default-property-inclusion")
public JsonInclude.Include getSerializationInclusion() {
return this.serializationInclusion;
return getDefaultPropertyInclusion();
}
@Deprecated
public void setSerializationInclusion(JsonInclude.Include serializationInclusion) {
this.serializationInclusion = serializationInclusion;
setDefaultPropertyInclusion(serializationInclusion);
}
public JsonInclude.Include getDefaultPropertyInclusion() {
return this.defaultPropertyInclusion;
}
public void setDefaultPropertyInclusion(
JsonInclude.Include defaultPropertyInclusion) {
this.defaultPropertyInclusion = defaultPropertyInclusion;
}
public TimeZone getTimeZone() {

View File

@@ -35,7 +35,7 @@ import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy;
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;
@@ -167,22 +167,22 @@ public class JacksonAutoConfigurationTests {
public void customPropertyNamingStrategyField() throws Exception {
this.context.register(JacksonAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.jackson.property-naming-strategy:CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES");
"spring.jackson.property-naming-strategy:SNAKE_CASE");
this.context.refresh();
ObjectMapper mapper = this.context.getBean(ObjectMapper.class);
assertThat(mapper.getPropertyNamingStrategy())
.isInstanceOf(LowerCaseWithUnderscoresStrategy.class);
.isInstanceOf(SnakeCaseStrategy.class);
}
@Test
public void customPropertyNamingStrategyClass() throws Exception {
this.context.register(JacksonAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.jackson.property-naming-strategy:com.fasterxml.jackson.databind.PropertyNamingStrategy.LowerCaseWithUnderscoresStrategy");
"spring.jackson.property-naming-strategy:com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy");
this.context.refresh();
ObjectMapper mapper = this.context.getBean(ObjectMapper.class);
assertThat(mapper.getPropertyNamingStrategy())
.isInstanceOf(LowerCaseWithUnderscoresStrategy.class);
.isInstanceOf(SnakeCaseStrategy.class);
}
@Test
@@ -355,8 +355,8 @@ public class JacksonAutoConfigurationTests {
this.context.refresh();
ObjectMapper objectMapper = this.context
.getBean(Jackson2ObjectMapperBuilder.class).build();
assertThat(objectMapper.getSerializationConfig().getSerializationInclusion())
.isEqualTo(JsonInclude.Include.ALWAYS);
assertThat(objectMapper.getSerializationConfig().getDefaultPropertyInclusion()
.getValueInclusion()).isEqualTo(JsonInclude.Include.USE_DEFAULTS);
}
@Test
@@ -367,8 +367,8 @@ public class JacksonAutoConfigurationTests {
this.context.refresh();
ObjectMapper objectMapper = this.context
.getBean(Jackson2ObjectMapperBuilder.class).build();
assertThat(objectMapper.getSerializationConfig().getSerializationInclusion())
.isEqualTo(JsonInclude.Include.NON_NULL);
assertThat(objectMapper.getSerializationConfig().getDefaultPropertyInclusion()
.getValueInclusion()).isEqualTo(JsonInclude.Include.NON_NULL);
}
@Test

View File

@@ -112,9 +112,9 @@ public class DataSourceJsonSerializationTests {
for (BeanPropertyWriter writer : beanProperties) {
AnnotatedMethod setter = beanDesc.findMethod(
"set" + StringUtils.capitalize(writer.getName()),
new Class<?>[] { writer.getPropertyType() });
new Class<?>[] { writer.getType().getRawClass() });
if (setter != null && this.conversionService.canConvert(String.class,
writer.getPropertyType())) {
writer.getType().getRawClass())) {
result.add(writer);
}
}