Javascript date for java.time.LocalDate
I am trying to send json data to a controller in Java.
This is my controller:
@ResponseBody
@RequestMapping(value="/{schoolId}", method=RequestMethod.POST)
public ClassGroupDTO addClassGroup(@RequestBody ClassGroupDTO classgroup, @PathVariable Integer schoolId) {
return partyService.addClassGroup(classgroup, schoolId);
}
This is the ClassGroupDTO class
public class ClassGroupDTO extends PartyDTO {
private PartyDTO titular;
private SiteDTO site;
@JsonDeserialize(using = LocalDateDeserializer.class)
private LocalDate startDate;
@JsonDeserialize(using = LocalDateDeserializer.class)
private LocalDate endDate;
...
}
I am using Jackson 2.4.3.
I cannot send data when the startDate or endDate field is set. I've tried several post formats. (I am using moment.js)
data.startDate = moment().toDate();
data.startDate = moment().toJSON();
data.startDate = moment().format("YYYY/MM/DD");
Every time I get a Bad Request error. When I leave startDate or endDate, the data is sent and the controller starts.
How to deserialize javascript date for java.time.LocalDate?
+3
source to share
1 answer