Jackson is ignoring spring.jackson.properties in my spring boot application

后端 未结 6 1248
没有蜡笔的小新
没有蜡笔的小新 2021-02-19 06:01

Jackson is ignoring spring.jackson.property-naming-strategy=SNAKE_CASE. I am using springBootVersion 1.4.2.RELEASE. In my application.properties file, I have added

6条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-19 06:49

    Just like @skadya's answer, I update it in new spring version and Java 8 styles.

    @EnableWebMvc
    @Configuration
    public class WebConfig implements WebMvcConfigurer {
        private ObjectMapper mapper;
    
        @Autowired  // spring.jackson.* ObjectMapper's config
        public WebConfig(ObjectMapper mapper) {
            this.mapper = mapper;
        }
    
        @Override
        public void extendMessageConverters (List> converters) {
            converters.stream()
                    .filter(x -> x instanceof  MappingJackson2HttpMessageConverter)
                    .forEach(x -> ((MappingJackson2HttpMessageConverter) x).setObjectMapper(mapper));
        }
    }
    

提交回复
热议问题