5

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
7
  • Did you compile with debugging enabled? Otherwise, your parameter names will not be available. 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 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 of POST. Commented Oct 12, 2012 at 15:34
  • @Lion jackson, it works for one paramter. Restful api should only use GET you say ? Debatable : stackoverflow.com/q/11522946/106261 Commented Oct 12, 2012 at 15:37
  • so my json looks right to everyone ? Commented Oct 12, 2012 at 15:38

1 Answer 1

4

Your 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.

Sign up to request clarification or add additional context in comments.

8 Comments

is there no other way ? I assumed spring coul dhandle multple request paramters ?
It can but its not a request parameter what you have is the body of the request
I have tried with both annoations. Neither is working. How can I do it using two method paramters ... ?
What are the both ways? I see only one. Check also that the content type is application/json. You cant, its not supposed toi work that way
Annoating method parameters with both requestparam, and requestbody ... OK, so I have to wrap in wrapper bject and change method signature.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.