How can I change Jacksons Configuration when using Spring Data REST?

前端 未结 4 959
予麋鹿
予麋鹿 2021-01-16 09:37

I\'m trying to configure Jackson to show JSR 310 instants in ISO 8601 format.

@Configuration
class Jackson {

    @Bean
    static ObjectMapper objectMapper(         


        
4条回答
  •  野的像风
    2021-01-16 10:19

    After some experimentation, I found that if I annotate my "setter" (setter injection) with it will get run. This is a little simpler, and cleaner than using field injection and @PostConstruct.

    @Configuration
    class Jackson {
    
       @Autowired
       void configureObjectMapper( final ObjectMapper objectMapper ) {
        objectMapper.disable( SerializationFeature.WRITE_DATES_AS_TIMESTAMPS );
       }
    }
    

提交回复
热议问题