4

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

16
  • Where are you creating the ObjectMapper instance, in a java class file or in the spring config? Commented Jun 6, 2017 at 10:36
  • 1
    It is automatically created by spring-boot or spring-mvc, and should thereby use the configuration properties during initialization. Commented Jun 6, 2017 at 10:45
  • I think you need to change your tags to add spring-boot Commented Jun 6, 2017 at 10:47
  • 1
    What you are trying is data binding which does nothing with Jackson. You are passing URL parameters whereas the Jackson serializer/mapper will only be active for response bodies NOT parameters. Commented Jun 6, 2017 at 11:38
  • 1
    I'm able to replicate on 1.5.3.RELEASE version. Commented Jun 6, 2017 at 11:44

2 Answers 2

5

According to spring doc you can customize it.

I fix this problem by set my application.yml like this(spring 2.0):

 spring: jackson: mapper: ACCEPT_CASE_INSENSITIVE_PROPERTIES: true 

Did you tried change your setting accept_case_insensitive_properties to UPPER CASE?

Also you can keep output to Upper Case by setting like this:

 jackson: mapper: ACCEPT_CASE_INSENSITIVE_PROPERTIES: true property-naming-strategy: com.fasterxml.jackson.databind.PropertyNamingStrategy.PascalCaseStrategy 

Note that PascalCaseStrategy was deprecated now, but still working.

Sign up to request clarification or add additional context in comments.

1 Comment

Current version of spring/spring-boot uses spring.jackson.mapper.accept-case-insensitive-properties=true (hyphens not underscores for the property name; not sure if case-sensitive or not).
1

Simple answer: it is not possible.

The Jackson2ObjectMapperBuilderCustomizer affects the JSON POST requests only. It has no effect on the get query binding.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.