Controller signature (I have tried as requestbody as well) :
@RequestMapping(value = "/Lame", method = RequestMethod.POST)
public
@ResponseBody
boolean getLame(@RequestParam String strToMatchA, @RequestParam String strToMatchB) {}
And this as my json :
{
"strToMatchA": "EN",
"strToMatchB": "lon"
}
Not working, I receive the error :
org.springframework.web.bind.MissingServletRequestParameterException: Required String parameter 'strToMatchA' is not present
Removing this first parameter from method signature then makes it work (the method gets called correctly), what should I be doing ?
When I change method parameters to be annotated with @RequestBody
I get the following error :
java.io.IOException: Stream closed
Controller signature (I have tried as requestbody as well) :
@RequestMapping(value = "/Lame", method = RequestMethod.POST)
public
@ResponseBody
boolean getLame(@RequestParam String strToMatchA, @RequestParam String strToMatchB) {}
And this as my json :
{
"strToMatchA": "EN",
"strToMatchB": "lon"
}
Not working, I receive the error :
org.springframework.web.bind.MissingServletRequestParameterException: Required String parameter 'strToMatchA' is not present
Removing this first parameter from method signature then makes it work (the method gets called correctly), what should I be doing ?
When I change method parameters to be annotated with @RequestBody
I get the following error :
java.io.IOException: Stream closed
Share
Improve this question
edited Oct 12, 2012 at 15:56
NimChimpsky
asked Oct 12, 2012 at 15:26
NimChimpskyNimChimpsky
47.3k61 gold badges201 silver badges317 bronze badges
7
- Did you pile with debugging enabled? Otherwise, your parameter names will not be available. – David Grant Commented Oct 12, 2012 at 15:29
- @DavidGrant RequestParam will take parameter name defined in method signature. But I have tried whilst manually specify name too – NimChimpsky Commented Oct 12, 2012 at 15:32
-
1
Which library are you using for object-mapping? Is it Jackson or something else? Is it on the classpath? Additionally, the request method for RESTFul controllers should basically be
GET
instead ofPOST
. – Lion Commented Oct 12, 2012 at 15:34 - @Lion jackson, it works for one paramter. Restful api should only use GET you say ? Debatable : stackoverflow./q/11522946/106261 – NimChimpsky Commented Oct 12, 2012 at 15:37
- so my json looks right to everyone ? – NimChimpsky Commented Oct 12, 2012 at 15:38
1 Answer
Reset to default 4Your json is fine but not the controller signature. Create a class with setters matching the json. Use it as argument instead of your strings. Annotate it with requestbody. It should work.