I have a dialog with a list of generated fields whose names contain the primary id of the user to which the data belongs. I am creating a JSON object with the data from these fields and posting it to a Spring Controller. Since the JSON does not have keys that can be matched to any specific attribute in a custom object, what type of object should I cast it to in order to most easily iterate through the object on the server side? As it is currently coded I am attempting to allow Spring to parse the object. Is there possibly a better design pattern that would be a cleaner approach?
This is my json:
({'1234567890_testID':"432342342", '0987654321_testID':"345353453"})
The value for each record will be saved for the user with the id which makes up the prefix of the key _testID. There are potentially other types of keys as well, eg: 1203048829_otherTestID.
Here's my code:
Javascript:
var $testID = $('#testDIV input');
var testData = {};
$testID.each(function(i, el) {
testData[$(el).attr("id")] = $(el).val();
});
var params= $.extend({ "tableID" : "testTable" }, {"testData" : testData.toSource()});
$.ajax({ "dataType": "json",
"type": "put",
"url": this.url,
"data": params,
"success": function(alert("Success!"))
})
Controller method signature:
@RequestMapping(value="/test", method=RequestMethod.PUT)
public @ResponseBody String updateTest(@ModelAttribute final TestCriteria tc)
ModelAttribute bean:
public class TestCriteria {
private Map<String, Object> testData;
getters and setters...
}
Firebug parameters:
action PUT testData ({'100540718367_testID':"432342342", '100540718371_testID':"252535345"}) tableID testTable