Hello,
I'm using Spring MVC 3.0.3 on backend and Ext JS on frontend.
When creating a new record in grid, Ext send a POST request with following JSON string:
{"data":{"name":"aa","label":"a","description":"a" }}
The record is wrapped in a JSON object named "data".
From what I have seen and read, Spring Jackson message converter expects the objet directly as below:
I implemented a wrapper class ExtJsRequest in order to mimic the JSON wrapping.Code:{"name":"aa","label":"a","description":"a"}
And I used @RequestBody as below:Code:public class ExtJsRequest { private Application data; public void setData(Application data) { this.data = data; } public Application getData() { return data; } }
An alternative would be to customize the Ext.data.JsonWriter to suppress object wrapping on client side.Code:@RequestMapping(value = "/application", method = POST) public ModelAndView create(@RequestBody ExtJsRequest extRequest, HttpServletResponse response) { ... }
But I was wondering if there is a more convenient way to do it in Spring: in the controller or message converter?
Thanks,
Phil


Reply With Quote
