Set Jackson DEFAULT_VIEW_INCLUSION property to false by default

Issue: SPR-12179
This commit is contained in:
Sebastien Deleuze
2014-09-30 05:07:31 +02:00
parent 42aef5f5dc
commit 77abe07807
11 changed files with 35 additions and 17 deletions

View File

@@ -47,6 +47,12 @@ import org.springframework.util.ClassUtils;
/**
* A builder used to create {@link ObjectMapper} instances with a fluent API.
*
* <p>It customizes Jackson defaults properties with the following ones:
* <ul>
* <li>{@link MapperFeature#DEFAULT_VIEW_INCLUSION} is disabled</li>
* <li>{@link DeserializationFeature#FAIL_ON_UNKNOWN_PROPERTIES} is disabled</li>
* </ul>
*
* <p>Note that Jackson's JSR-310 and Joda-Time support modules will be registered automatically
* when available (and when Java 8 and Joda-Time themselves are available, respectively).
*
@@ -384,6 +390,9 @@ public class Jackson2ObjectMapperBuilder {
this.objectMapper.registerModule(module);
}
if(!features.containsKey(MapperFeature.DEFAULT_VIEW_INCLUSION)) {
configureFeature(MapperFeature.DEFAULT_VIEW_INCLUSION, false);
}
if(!features.containsKey(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)) {
configureFeature(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}

View File

@@ -52,6 +52,12 @@ import org.springframework.util.ClassUtils;
* {@link XmlMapper} ({@code createXmlMapper} property set to true) with setters
* to enable or disable Jackson features from within XML configuration.
*
* <p>It customizes Jackson defaults properties with the following ones:
* <ul>
* <li>{@link MapperFeature#DEFAULT_VIEW_INCLUSION} is disabled</li>
* <li>{@link DeserializationFeature#FAIL_ON_UNKNOWN_PROPERTIES} is disabled</li>
* </ul>
*
* <p>Example usage with
* {@link MappingJackson2HttpMessageConverter}:
*
@@ -413,6 +419,9 @@ public class Jackson2ObjectMapperFactoryBean implements FactoryBean<ObjectMapper
this.objectMapper.registerModule(module);
}
if(!features.containsKey(MapperFeature.DEFAULT_VIEW_INCLUSION)) {
configureFeature(MapperFeature.DEFAULT_VIEW_INCLUSION, false);
}
if(!features.containsKey(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)) {
configureFeature(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}