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


I have the same problem, it was solved with:

var dateString = new Date().toISOString().substring(0,10);

      

or



var dateString = new Date().toISOString().split("T")[0];

      

Convert to ISO string ("2015-10-14T09: 39: 49.942Z"), then keep only the first ten characters, ie date.

+3


source







All Articles