Issue
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
spring.jackson.property-naming-strategy=SNAKE_CASE
But Jackson is not honoring this property, and my REST response is still camelCase. Interestingly, this annotation works just fine
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy.class)
With this annotation, I am getting snake_case response. But I don't want to annotate each response class, it's a bit annoying.
Edit
I tried using fully qualified class name as well,
spring.jackson.property-naming-strategy=com.fasterxml.jackson.databind.PropertyNamingStrategy.SnakeCaseStrategy
that did not work either
Solution
I had @EnableWebMvc
annotation in one of the classes (ExceptionHandler) in my Application (face-palm!).
But, as per this issue,
If you have @EnableWebMvc annotation, that disables the auto-configuration of Spring MVC, including the configuring of its message converters to customize Jackson's serialization.
It's expected behavior when you use @EnableWebMvc as, by doing so, you're telling Spring Boot that you want to take control of Spring MVC's configuration. That includes configuring its HTTP message converters to (de)serialize JSON in the manner that meets your needs.
If you want to override the Jackson configuration, you can either use the spring.jackson.* properties or, if you want more control, declare your own Jackson2ObjectMapperBuilder bean.
Once I removed @EnableWebMvc
annotation, this property works as expected.
Answered By - so-random-dude