Reputation: 147
I am writing a plain post request using spring boot web module, and the fields in my POST request are name, Description and title.
My question is when i use postman or any client to make a POST request to add a new entity, the json keys, name, Description and title are case sensitive, but how can i make the keys case-insensitive. in other words, even when user makes a post request using description instead of Description my application should accept the value and rather not take null since it was not exact match.
Any thoughts are appreciated
Upvotes: 1
Views: 657
Reputation: 1026
You can write function to check your keys are present with case sensitive values or not. In get method you can call method to pick the key.
public String getIgnoreCase(JSONObject obj, String key) {
Iterator<String> itr = obj.keySet().iterator();
while (itr.hasNext()) {
String key1 = itr.next();
if (key1.equalsIgnoreCase(key)) {
return obj.get(key1);
}
}
return null;
}
Upvotes: 0
Reputation: 9457
If u want to keep @RequestBody Item item. then here is solution:
in application.properties:
spring.jackson.mapper.accept_case_insensitive_properties=true
if you use application.yml then:
spring:
jackson:
mapper:
accept_case_insensitive_properties: true
Upvotes: 0