I\'m using SpringMVC and have the following Method.
@RequestMapping(\"/login\")
public @ResponseBody User login(User user) {
// some operation here ....
Below posting an example for deserializing json Array to Arraylist
@RequestMapping(value = "/mapJsonObjects", method = RequestMethod.POST)
public static ModelAndView parseJSONObjects(@RequestParam String jsonList,HttpServletRequest request,
HttpServletResponse response) throws Exception {
JSONParser parser=new JSONParser();
ArrayList filteredList = new ArrayList();
Object obj = parser.parse(jsonList);
JSONArray newList = (JSONArray)obj;
filteredList = newList;
-----------
}
To convert an array List to json array. First add the below beans to springServlet.xml
text/html
Then from the controller return the arraylist as below
Map filteredMap = new LinkedHashMap();
List filteredList;
------filteredMap logic -----------
filteredAccountMap.put("rows", filteredList);
return new ModelAndView("jsonView", filteredMap);