Issue
I want to enable the following jackson mapper feature:
MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES
According to https://docs.spring.io/spring-boot/docs/current/reference/html/howto-spring-mvc.html:
Could be configured in application.properties
as follows:
spring.jackson.mapper.accept_case_insensitive_properties=true
But:
@RestController
public class MyServlet {
@RequestMapping("/test")
public void test(@Valid TestReq req) {
}
}
public class TestReq {
@NotBlank
private String name;
}
Usage:
localhost:8080/test?name=test //works
localhost:8080/test?Name=test //fails with 'name may not be blank'
So, the case insensitive property is not taken into account. But why?
By the way: even using Jackson2ObjectMapperBuilderCustomizer
explicit does not work:
@Bean
public Jackson2ObjectMapperBuilderCustomizer initJackson() {
Jackson2ObjectMapperBuilderCustomizer c = new Jackson2ObjectMapperBuilderCustomizer() {
@Override
public void customize(Jackson2ObjectMapperBuilder builder) {
builder.featuresToEnable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES);
}
};
return c;
}
spring-boot-1.5.3.RELEASE
Solution
Simple answer: it is not possible.
The Jackson2ObjectMapperBuilderCustomizer
affects the JSON POST requests only. It has no effect on the get query binding.
Answered By - membersound