Configuring ObjectMapper in Spring

前端 未结 12 1936
迷失自我
迷失自我 2020-11-22 10:46

my goal is to configure the objectMapper in the way that it only serialises element which are annotated with @JsonProperty.

In order to do

12条回答
  •  无人共我
    2020-11-22 11:25

    Using Spring Boot (1.2.4) and Jackson (2.4.6) the following annotation based configuration worked for me.

    @Configuration
    public class JacksonConfiguration {
    
        @Bean
        public ObjectMapper objectMapper() {
            ObjectMapper mapper = new ObjectMapper();
            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
            mapper.configure(MapperFeature.DEFAULT_VIEW_INCLUSION, true);
    
            return mapper;
        }
    }
    

提交回复
热议问题