Ho un endpoint REST nella mia applicazione primavera che assomiglia a questoZonedDateTime come PathVariable nella primavera REST RequestMapping
@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 ...
}
ho provato passando nelle variabili di percorso sia come millisecondi e secondi. Tuttavia, ottengo la seguente eccezione in entrambi i modi:
"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"
Qualcuno può spiegare come posso passare a (o come secondi o millisecondi) una stringa come 1446,3612 milioni e farlo convertire a ZonedDateTime?
Oppure è l'unico modo per passare come String e quindi effettuare la conversione da solo? Se è così esiste un modo generico per ottenere questo trattamento per più metodi con design simile?
'ZonedDateTime' è relativamente nuovo e Spring probabilmente non è stato aggiornato per supportarlo direttamente. Vedi la risposta di JasonZ per una soluzione alternativa a questo. – Powerlord