I have a simple POJO Java class (getters and setters is not shown)
public class VacationInfo {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Temporal(TemporalType.TIMESTAMP)
private Date vacationFrom;
@Temporal(TemporalType.TIMESTAMP)
private Date vacationTo;
, Spring MVC controller with next method
@RequestMapping(value = "updateVacations", method = RequestMethod.POST)
public String updateVacations(@RequestParam VacationInfo[] vacationInfos) {
...
}
and jQuery post request
$.ajax({
type: "POST",
url: "updateVacations",
dataType: 'json',
data: vacationInfos
});
where "vacationInfos" is a array with JSON objects, which represent VacationInfo class:
[
{
vacationFrom: "01-01-2013",
vacationTo: "01-01-2013"
},
{
vacationFrom: "01-01-2013",
vacationTo: "01-01-2013"
}
]
But when I do request - i got a HTTP 400 error.
dataTypeoption signifies the type of the response expected from the server, not the type of data being sent. In addition, thedataoption is expected to either be an object of key-value pairs, or the query string for the request; I don't think passing an array of objects would be handled correctly. You could try: `data: {vacationInfos : vacationInfos}, then modify your server-side code to use that single parameter.