I have a string : “14 Feb 2012” that I want to des

2019-08-22 04:49发布

问题:

How do I create my own json mapping serialization/desrialization ?

Using spring 3.1 annotions.

@RequestMapping(value = "/Save", method = RequestMethod.POST)
public String saveDTO(@Valid @RequestBody final myDTO myDTO,Model model){

where myDTO contains a LocalDate, and I have correctly created the json using jquery/javascript, the error message is so :

Caused by: java.lang.IllegalArgumentException: Invalid format: "14-Feb-2012" is malformed 
at "-Feb-2012" at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:866)

回答1:

Did you try adding @DateTimeFormat annotation to LocalDate with this date format dd-MMM-yyyy i.e.

@DateTimeFormat(pattern = "dd-MMM-yyyy")
Date LocalDate;