I have a REST endpoint in my Spring application that looks like this
@RequestMapping(value="/customer/device/startDate/{startDate}/endDate/{endDate}", method=RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE)
public Page<DeviceInfo> getDeviceListForCustomerBetweenDates(@PathVariable ZonedDateTime startDate, @PathVariable ZonedDateTime endDate, Pageable pageable) {
... code here ...
}
I have tried passing in the path variables as both milliseconds and seconds. However, I get the following exception both ways:
"Failed to convert value of type 'java.lang.String' to required type 'java.time.ZonedDateTime'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type java.lang.String to type @org.springframework.web.bind.annotation.PathVariable java.time.ZonedDateTime for value '1446361200'; nested exception is java.time.format.DateTimeParseException: Text '1446361200' could not be parsed at index 10"
Can someone please explain how I can pass in (either as seconds or milliseconds) a String such as 1446361200 and get it to convert to ZonedDateTime?
Or is the only way to pass as String and then do the conversion myself? If so is there a generic way to get this handled for multiple methods with similar design?