How do you instantiate a custom object from a request param? (I have tried both @ModelAttribute and @RequestParam)
@RequestMapping(method = RequestMethod.POST)
public String newPerson(@ModelAttribute(value = "personModel")
Person person, BindingResult result) {
// Person has just firstname and lastname fields
}
I try to call this with jQuery using the following code:
var PersonText = '["firstname":"John", "lastname":"Someone"]';
$.ajax({
type : 'POST',
url : "/addnewperson.do",
data : {'personModel' : personText},
datatype : 'json',
success : function(data) {
var obj = jQuery.parseJSON(data);
}
});
In fact my original plan was to send an entire list of person objects over to the controller, but since that didn't work I reverted back to a single object, but now that doesn't work either.
EDIT: the param doesn't have to be JSON, I just thought it would make sense to serialize the Javascript object as JSON over to the Spring Controller.