Set Jackson FAIL_ON_UNKNOWN_PROPERTIES property to false by default
Issue: SPR-11891
This commit is contained in:
parent
4e24d66ff7
commit
42aef5f5dc
|
|
@ -384,6 +384,9 @@ public class Jackson2ObjectMapperBuilder {
|
||||||
this.objectMapper.registerModule(module);
|
this.objectMapper.registerModule(module);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!features.containsKey(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)) {
|
||||||
|
configureFeature(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
}
|
||||||
for (Object feature : this.features.keySet()) {
|
for (Object feature : this.features.keySet()) {
|
||||||
configureFeature(feature, this.features.get(feature));
|
configureFeature(feature, this.features.get(feature));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -413,6 +413,9 @@ public class Jackson2ObjectMapperFactoryBean implements FactoryBean<ObjectMapper
|
||||||
this.objectMapper.registerModule(module);
|
this.objectMapper.registerModule(module);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!features.containsKey(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)) {
|
||||||
|
configureFeature(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
|
}
|
||||||
for (Object feature : this.features.keySet()) {
|
for (Object feature : this.features.keySet()) {
|
||||||
configureFeature(feature, this.features.get(feature));
|
configureFeature(feature, this.features.get(feature));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||||
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build();
|
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().build();
|
||||||
assertNotNull(objectMapper);
|
assertNotNull(objectMapper);
|
||||||
assertTrue(objectMapper.isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
|
assertTrue(objectMapper.isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
|
||||||
assertTrue(objectMapper.isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
|
assertFalse(objectMapper.isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
|
||||||
assertTrue(objectMapper.isEnabled(MapperFeature.AUTO_DETECT_FIELDS));
|
assertTrue(objectMapper.isEnabled(MapperFeature.AUTO_DETECT_FIELDS));
|
||||||
assertTrue(objectMapper.isEnabled(MapperFeature.AUTO_DETECT_GETTERS));
|
assertTrue(objectMapper.isEnabled(MapperFeature.AUTO_DETECT_GETTERS));
|
||||||
assertTrue(objectMapper.isEnabled(MapperFeature.AUTO_DETECT_SETTERS));
|
assertTrue(objectMapper.isEnabled(MapperFeature.AUTO_DETECT_SETTERS));
|
||||||
|
|
@ -241,7 +241,7 @@ public class Jackson2ObjectMapperBuilderTests {
|
||||||
|
|
||||||
assertFalse(objectMapper.getSerializationConfig().isEnabled(MapperFeature.AUTO_DETECT_GETTERS));
|
assertFalse(objectMapper.getSerializationConfig().isEnabled(MapperFeature.AUTO_DETECT_GETTERS));
|
||||||
assertTrue(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
|
assertTrue(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
|
||||||
assertTrue(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
|
assertFalse(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
|
||||||
assertFalse(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.AUTO_DETECT_FIELDS));
|
assertFalse(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.AUTO_DETECT_FIELDS));
|
||||||
assertFalse(objectMapper.getFactory().isEnabled(JsonParser.Feature.AUTO_CLOSE_SOURCE));
|
assertFalse(objectMapper.getFactory().isEnabled(JsonParser.Feature.AUTO_CLOSE_SOURCE));
|
||||||
assertFalse(objectMapper.getFactory().isEnabled(JsonGenerator.Feature.QUOTE_FIELD_NAMES));
|
assertFalse(objectMapper.getFactory().isEnabled(JsonGenerator.Feature.QUOTE_FIELD_NAMES));
|
||||||
|
|
|
||||||
|
|
@ -260,7 +260,7 @@ public class Jackson2ObjectMapperFactoryBeanTests {
|
||||||
|
|
||||||
assertFalse(objectMapper.getSerializationConfig().isEnabled(MapperFeature.AUTO_DETECT_GETTERS));
|
assertFalse(objectMapper.getSerializationConfig().isEnabled(MapperFeature.AUTO_DETECT_GETTERS));
|
||||||
assertTrue(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
|
assertTrue(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
|
||||||
assertTrue(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
|
assertFalse(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
|
||||||
assertFalse(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.AUTO_DETECT_FIELDS));
|
assertFalse(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.AUTO_DETECT_FIELDS));
|
||||||
assertFalse(objectMapper.getFactory().isEnabled(JsonParser.Feature.AUTO_CLOSE_SOURCE));
|
assertFalse(objectMapper.getFactory().isEnabled(JsonParser.Feature.AUTO_CLOSE_SOURCE));
|
||||||
assertFalse(objectMapper.getFactory().isEnabled(JsonGenerator.Feature.QUOTE_FIELD_NAMES));
|
assertFalse(objectMapper.getFactory().isEnabled(JsonGenerator.Feature.QUOTE_FIELD_NAMES));
|
||||||
|
|
|
||||||
|
|
@ -146,12 +146,13 @@ public class MappingJackson2HttpMessageConverterTests {
|
||||||
converter.read(MyBean.class, inputMessage);
|
converter.read(MyBean.class, inputMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = HttpMessageNotReadableException.class)
|
@Test
|
||||||
public void readValidJsonWithUnknownProperty() throws IOException {
|
public void readValidJsonWithUnknownProperty() throws IOException {
|
||||||
String body = "{\"string\":\"string\",\"unknownProperty\":\"value\"}";
|
String body = "{\"string\":\"string\",\"unknownProperty\":\"value\"}";
|
||||||
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
|
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
|
||||||
inputMessage.getHeaders().setContentType(new MediaType("application", "json"));
|
inputMessage.getHeaders().setContentType(new MediaType("application", "json"));
|
||||||
converter.read(MyBean.class, inputMessage);
|
converter.read(MyBean.class, inputMessage);
|
||||||
|
// Assert no HttpMessageNotReadableException is thrown
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -102,12 +102,13 @@ public class MappingJackson2XmlHttpMessageConverterTests {
|
||||||
converter.read(MyBean.class, inputMessage);
|
converter.read(MyBean.class, inputMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = HttpMessageNotReadableException.class)
|
@Test
|
||||||
public void readValidXmlWithUnknownProperty() throws IOException {
|
public void readValidXmlWithUnknownProperty() throws IOException {
|
||||||
String body = "<MyBean><string>string</string><unknownProperty>value</unknownProperty></MyBean>";
|
String body = "<MyBean><string>string</string><unknownProperty>value</unknownProperty></MyBean>";
|
||||||
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
|
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
|
||||||
inputMessage.getHeaders().setContentType(new MediaType("application", "xml"));
|
inputMessage.getHeaders().setContentType(new MediaType("application", "xml"));
|
||||||
converter.read(MyBean.class, inputMessage);
|
converter.read(MyBean.class, inputMessage);
|
||||||
|
// Assert no HttpMessageNotReadableException is thrown
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -175,7 +175,7 @@ public class MvcNamespaceTests {
|
||||||
ObjectMapper objectMapper = ((AbstractJackson2HttpMessageConverter)converter).getObjectMapper();
|
ObjectMapper objectMapper = ((AbstractJackson2HttpMessageConverter)converter).getObjectMapper();
|
||||||
assertTrue(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
|
assertTrue(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
|
||||||
assertTrue(objectMapper.getSerializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
|
assertTrue(objectMapper.getSerializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
|
||||||
assertTrue(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
|
assertFalse(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
|
||||||
if(converter instanceof MappingJackson2XmlHttpMessageConverter) {
|
if(converter instanceof MappingJackson2XmlHttpMessageConverter) {
|
||||||
assertEquals(XmlMapper.class, objectMapper.getClass());
|
assertEquals(XmlMapper.class, objectMapper.getClass());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -162,12 +162,9 @@ public class WebMvcConfigurationSupportExtensionTests {
|
||||||
assertEquals(1, adapter.getMessageConverters().size());
|
assertEquals(1, adapter.getMessageConverters().size());
|
||||||
assertEquals(MappingJackson2HttpMessageConverter.class, adapter.getMessageConverters().get(0).getClass());
|
assertEquals(MappingJackson2HttpMessageConverter.class, adapter.getMessageConverters().get(0).getClass());
|
||||||
ObjectMapper objectMapper = ((MappingJackson2HttpMessageConverter)adapter.getMessageConverters().get(0)).getObjectMapper();
|
ObjectMapper objectMapper = ((MappingJackson2HttpMessageConverter)adapter.getMessageConverters().get(0)).getObjectMapper();
|
||||||
assertTrue(objectMapper.getDeserializationConfig()
|
assertTrue(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
|
||||||
.isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
|
assertTrue(objectMapper.getSerializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
|
||||||
assertTrue(objectMapper.getSerializationConfig()
|
assertFalse(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
|
||||||
.isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
|
|
||||||
assertTrue(objectMapper.getDeserializationConfig()
|
|
||||||
.isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
|
|
||||||
|
|
||||||
DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(adapter);
|
DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(adapter);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,7 @@ public class WebMvcConfigurationSupportTests {
|
||||||
ObjectMapper objectMapper = ((AbstractJackson2HttpMessageConverter)converter).getObjectMapper();
|
ObjectMapper objectMapper = ((AbstractJackson2HttpMessageConverter)converter).getObjectMapper();
|
||||||
assertTrue(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
|
assertTrue(objectMapper.getDeserializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
|
||||||
assertTrue(objectMapper.getSerializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
|
assertTrue(objectMapper.getSerializationConfig().isEnabled(MapperFeature.DEFAULT_VIEW_INCLUSION));
|
||||||
assertTrue(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
|
assertFalse(objectMapper.getDeserializationConfig().isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES));
|
||||||
if(converter instanceof MappingJackson2XmlHttpMessageConverter) {
|
if(converter instanceof MappingJackson2XmlHttpMessageConverter) {
|
||||||
assertEquals(XmlMapper.class, objectMapper.getClass());
|
assertEquals(XmlMapper.class, objectMapper.getClass());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue