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