3

I have a requirement to receive JSON with keys that contain underscore and even ignore the case in words. For e.g. Device_control_API, device_control_API, Device_Control_API, device_control_aPI etc all should map to same property.

Now I know that I can create multiple setter methods using @JsonSetter with all combinations possible, but I don't think that will be good.

I have seen other questions which suggest using mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true) for ObjectMapper object to ignore case, but I can't do that because I am using spring-boot and want my REST API to get payload in the form POJO object.

Is there any annotation or some way to do so

Please help !!!

2 Answers2

2

I dont think you can use the MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES as annotation. Got the following information from here

Jackson on/off features: MapperFeature

Jackson defines a set of per-mapper configuration, which can ONLY be defined before using ObjectMapper -- meaning that these settings can not be changed on-the-fly, on per-request basis. They configure fundamental POJO introspection details, and resulting built objects (serializers, deserializers, related) are heavily cached. If you need differing settings for these, you have to use separate ObjectMapper instances.

And the MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES is one of the configuration.


But maybe a custom deserialization class could help you. There are many tutorials and questions on Stackoverflow.

I found some:

Community
  • 1
  • 1
Patrick
  • 12,336
  • 15
  • 73
  • 115
1

There is also this property:

spring.jackson.mapper.accept_case_insensitive_properties=true

Frischling
  • 2,100
  • 14
  • 34