I have a form when submitted to a controller works fine, the controller signature :
@RequestMapping(value = "/Save", method = RequestMethod.POST)
public ModelAndView save(@ModelAttribute MyDTO myDTO) {}
I have another controller method for handling an ajax request with this signature:
@RequestMapping(value = "/Preview", method = RequestMethod.POST)
public ModelAndView preview(@RequestBody MyDTO myDTO) {}
However submitting the serialized form returns this error : org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "myList[0]" (Class myPackage.dto.MyDTO), not marked as ignorable
The javascript/jquery is :
var json = jq("#dtoForm").serializeObject();
json = JSON.stringify(json);
jq.ajax({
cache:false,
type: 'POST',
url: "${Preview}",
data:json,
contentType: "application/json",
success: function(data) {
previewDialog.html(data);
previewDialog.dialog('open');
}
});
What am I missing ? I am confused becuase the form submits fine (the dto is correctly mapped) when not converted json. The dto contains, amongst other things, a list.
Edit if I remove the json = JSON.stringify(json);
as suggested by springsource I get a slightly different error (one of the fields in dto is called "title"):
org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Unrecognized token 'til': was expecting 'null', 'true' or 'false'