mardi 3 mars 2015

Spring MVC post List of ImmutablePair with Ajax

I have a service method that takes List<ImmutablePair<Long, Long>> but can't get the controller to accept (bind? my jargon isn't great) the data. Simplified version of what I currently have:


Object:



public class Dto {
private List<ImmutablePair<Long, Long>> foo;

...getters and setters

}


Controller:



@RequestMapping(value = "list", method = RequestMethod.POST, headers = "Accept=application/json")
@ResponseBody
public String postInventoryList(@RequestBody Dto dto) {
...
}


JS:



$http.post(listUrl, JSON.stringify({foo: [{left:1, right:1}]})).then(function (result) {
console.log(result);
});


I can get it to work if I pass the pairs differently, but I'd really like to just use ImmutablePair to keep things clean and avoid having to process the data before calling that method. I'm guessing I need to tell Spring how to deal with this object type? How would I do this? Thanks!


Aucun commentaire:

Enregistrer un commentaire