mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
Upgrade to Jackson 2.12.0
See gh-24415
This commit is contained in:
parent
5fe5dc4860
commit
1f63b82c5b
@ -32,6 +32,7 @@ import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||
import com.fasterxml.jackson.databind.Module;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
|
||||
@ -257,10 +258,10 @@ public class JacksonAutoConfiguration {
|
||||
private void configurePropertyNamingStrategyField(Jackson2ObjectMapperBuilder builder, String fieldName) {
|
||||
// Find the field (this way we automatically support new constants
|
||||
// that may be added by Jackson in the future)
|
||||
Field field = ReflectionUtils.findField(PropertyNamingStrategy.class, fieldName,
|
||||
Field field = ReflectionUtils.findField(PropertyNamingStrategies.class, fieldName,
|
||||
PropertyNamingStrategy.class);
|
||||
Assert.notNull(field, () -> "Constant named '" + fieldName + "' not found on "
|
||||
+ PropertyNamingStrategy.class.getName());
|
||||
+ PropertyNamingStrategies.class.getName());
|
||||
try {
|
||||
builder.propertyNamingStrategy((PropertyNamingStrategy) field.get(null));
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ public class JacksonProperties {
|
||||
private String dateFormat;
|
||||
|
||||
/**
|
||||
* One of the constants on Jackson's PropertyNamingStrategy. Can also be a
|
||||
* One of the constants on Jackson's PropertyNamingStrategies. Can also be a
|
||||
* fully-qualified class name of a PropertyNamingStrategy subclass.
|
||||
*/
|
||||
private String propertyNamingStrategy;
|
||||
|
@ -37,7 +37,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.SnakeCaseStrategy;
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
@ -132,7 +132,7 @@ class JacksonAutoConfigurationTests {
|
||||
@Test
|
||||
void customPropertyNamingStrategyClass() {
|
||||
this.contextRunner.withPropertyValues(
|
||||
"spring.jackson.property-naming-strategy:com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy")
|
||||
"spring.jackson.property-naming-strategy:com.fasterxml.jackson.databind.PropertyNamingStrategies.SnakeCaseStrategy")
|
||||
.run((context) -> {
|
||||
ObjectMapper mapper = context.getBean(ObjectMapper.class);
|
||||
assertThat(mapper.getPropertyNamingStrategy()).isInstanceOf(SnakeCaseStrategy.class);
|
||||
|
@ -493,7 +493,7 @@ bom {
|
||||
]
|
||||
}
|
||||
}
|
||||
library("Jackson Bom", "2.11.3") {
|
||||
library("Jackson Bom", "2.12.0") {
|
||||
group("com.fasterxml.jackson") {
|
||||
imports = [
|
||||
"jackson-bom"
|
||||
|
@ -18,7 +18,7 @@ package org.springframework.boot.buildpack.platform.json;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
|
||||
|
||||
@ -37,7 +37,7 @@ public final class SharedObjectMapper {
|
||||
objectMapper.registerModule(new ParameterNamesModule());
|
||||
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
|
||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
objectMapper.setPropertyNamingStrategy(PropertyNamingStrategy.LOWER_CAMEL_CASE);
|
||||
objectMapper.setPropertyNamingStrategy(PropertyNamingStrategies.LOWER_CAMEL_CASE);
|
||||
INSTANCE = objectMapper;
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@ package org.springframework.boot.buildpack.platform.json;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategy;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;
|
||||
@ -42,9 +43,9 @@ class SharedObjectMapperTests {
|
||||
assertThat(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES
|
||||
.enabledIn(mapper.getDeserializationConfig().getDeserializationFeatures())).isFalse();
|
||||
assertThat(mapper.getSerializationConfig().getPropertyNamingStrategy())
|
||||
.isEqualTo(PropertyNamingStrategy.LOWER_CAMEL_CASE);
|
||||
.isEqualTo(PropertyNamingStrategies.LOWER_CAMEL_CASE);
|
||||
assertThat(mapper.getDeserializationConfig().getPropertyNamingStrategy())
|
||||
.isEqualTo(PropertyNamingStrategy.LOWER_CAMEL_CASE);
|
||||
.isEqualTo(PropertyNamingStrategies.LOWER_CAMEL_CASE);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user