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

前端 未结 4 960
予麋鹿
予麋鹿 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:18

    You can (and probably should) you RepositoryRestConfigurerAdapter (in Spring Data Rest 2.4) or RepositoryRestMvcConfiguration which expose the configureObjectMapper method.

    @Configuration
    class RepositoryRestAdapterConfiguration extends RepositoryRestConfigurerAdapter {
    
        @Override
        public void configureJacksonObjectMapper(ObjectMapper objectMapper) {
            objectMapper.registerModule(new JavaTimeModule());
            objectMapper.disable( SerializationFeature.WRITE_DATES_AS_TIMESTAMPS );
        }
    
    }
    

提交回复
热议问题