I have a Class
public class TestClass {
private String name;
private String id;
private String accountID;
}
Post Method:
@RequestMapping(value="/testclass", method=RequestMethod.POST)
public void create(@RequestBody TestClass testClass) {
//implementation using testClass
}
This works fine until the body in the request is as requires but When a POST call with body having multiple values of a variable, the @RequestBody takes the last given value of the variable. For Example:
POST call Body:
{
"name":"qwerty",
"id":"qw123"
"accountID":"111111",
"accountID":"222222",
"accountID":"333333",
"accountID":"444444"
}
then the testClass
object has values name=qwerty,id=qw123,accountID=444444
Thus, this allows any kind of request with any number of values in the body to be processed. Is it possible to identify this multiple values in the request so as to validate all the request prior to the implementation?
I.e I want the request to fail before reaching the code. I want to process the request only if it has single values. Also, it's not just about the given variables, the request may contain other variables as well , but the requestbody simply ignores it and takes the relevant variables alone. I want it to fail in that case too –