I have the code below:
DTO:
Class MyDTO { import java.util.Date; private Date dateOfBirth; public Date getDateOfBirth() { return dateOfBirth; } public void setDateOfBirth(Date dateOfBirth) { this.dateOfBirth = dateOfBirth; } }
controller
public void saveDOB(@RequestBody MyDTO myDTO, HttpServletRequest httprequest, HttpServletResponse httpResponse) { System.out.println("Inside Controller"); System.out.println(myDTO.getDateOfBirth()); }
JSON request:
{ "dateOfBirth":"2014-09-04", }
If I send the request as yyyy-mm-dd, it automatically converts to date. output signal in the controller: - dateOfBirth = Thursday, Thursday, 05:30:00 IST 2014
But when I send DateofBirth in dd-mm-yyyy format, it does not convert the string to date automatically. So how can I handle this thing.
JSON request:
{ "dateOfBirth":"04-09-2014", }
Conclusion: no Output to the console does not even reach the controller.
I tried with @DateTimeFormat but it does not work.
I am using Spring 4.02. Please suggest which annotations we can use.
source share