简体   繁体   中英

How to map JSON case insensitively from http POST request

I am using an http Post request with JSON to get request to my webservice. My problem is i want the JSON parameters to be case insensitive so that user can enter the parameters either in upper or lower case.

Is there any way to achieve this rather then using different setters for all paramters like in this link Case insensitive JSON to POJO mapping without changing the POJO

Here is my sample pojo:

public class SamplePojo implements Serializable
{
    String name;
    String mobileNo;
    String address;
}

Here is my web service

@RequestMapping(value = "/send", 
    method = RequestMethod.POST, 
    consumes = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody String trackSMSPost (@RequestBody SamplePojo sample) 
{
    process(sample);
    return "true";
}

Is there a way to get the request to the webservice even if parameter names are all uppercase or lowercase or camelcase.

According to the JSON-RPC specs

All names etc. are case-sensitive. Conforming implementations therefore MUST treat all names as being case-sensitive such the names "bar" and "BAR" would be seen as two distinct entities.

So basically convention dictates all names to be case-sensitive, if you really need case-insensitivity here your only options are dirty tricks (eg implementing getter-setters).

JSON is case-sensitive.
alternate
you can accept request as String and make it toUpperCase [Only valid if data is any Number Value] :-) kirti mandwade

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM