mardi 3 mars 2015

Spring MVC : post request and json object with array : bad request

I'm trying to retrieve parameters from a http POST request with Spring MVC.


The request contains the following json object (content-type : application/json), which itself contains an array of customObjects :



{
"globalId":"338",
"lines":[
{
"id": "someId",
"lib":"blabla",
...

}
]
}


Here's the code I'm trying to use :



@RequestMapping(method = RequestMethod.POST, value = "/valider")
@ResponseBody
public void valider(final HttpServletRequest request, @RequestParam("globalId") final String globalId, @RequestParam("lines") final MyCustomObject[] lines) {


All I'm getting is a "bad request" error (http 400).


Is it possible to separately retrieve the two parameters "globalId" and "lines" ? Or since they are in the same json object, it has to be treated has a single parameter ? How do you proceed when you have more than one parameter in a Post request ?


Aucun commentaire:

Enregistrer un commentaire