So I have a method where I want to take in some Dates which would be converted using the @DateTimeFormat annotations. Here is the method definition:
@RequestMapping( method = RequestMethod.GET)
@ResponseBody
public JsonUtil getAuditLog(
@RequestParam(value = "startDate", required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.Date_TIME) Date startDate,
@RequestParam(value = "endDate", required = false ) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) Date endDate,
@RequestParam(value = "page", defaultValue = "0") Integer page ) {
But I keep getting this:
java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'java.util.Date': no matching editors or conversion strategy found
So I tried this:
@RequestMapping( method = RequestMethod.GET)
@ResponseBody
public JsonUtil getAuditLog(
@RequestParam(value = "startDate", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSX") Date startDate,
@RequestParam(value = "endDate", required = false ) @DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSX") Date endDate,
@RequestParam(value = "page", defaultValue = "0") Integer page ) {
And that didn't work either. Same error. So I used that pattern with a SimpleDateFormat and manually convert the Date in my Controller. That worked! So why is @DateTimeFormat annotation NOT working? This is in SpringMVC not Spring Boot.