Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot Web- Set FAIL_ON_UNKNOWN_PROPERTIES to false in Jackson

I have read Spring boot doc (http://projects.spring.io/spring-boot/docs/docs/howto.html#message.converters ) and its mentioned that if you provide your own JacksonConvertor, it will override the default one. But I guess its not working with the below code.

What I want to do is to set DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES of the object mapper to false.

@EnableAutoConfiguration
@ComponentScan("com.hjh")
@Configuration
public class App {

    @Bean
    @Primary
    public MappingJackson2HttpMessageConverter jacksonConvertor(){
        MappingJackson2HttpMessageConverter convertor= new MappingJackson2HttpMessageConverter();
        ObjectMapper mapper = new ObjectMapper();
        mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
        convertor.setObjectMapper(mapper);
        return convertor;
    }

    public static void main(String[] args) throws Exception {
        ApplicationContext ctx =   SpringApplication.run(App.class, args);

    }

Could any one please point out what am i doing wrong here? As it keeps on trying to bind the unknown prop from the request. If I remove the unknown prop, it all goes well

like image 852
hellojava Avatar asked Jan 21 '14 15:01

hellojava


1 Answers

Starting from Spring Boot 1.2.0.RC2 FAIL_ON_UNKNOWN_PROPERTIES is set to false by default. It can be turned back on by adding property to application.properties:

spring.jackson.deserialization.fail-on-unknown-properties=true
like image 189
Maciej Walkowiak Avatar answered Oct 04 '22 13:10

Maciej Walkowiak