私はこのZonedDateTime
@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 ...
}
のように見える私のSpringアプリケーションでのRESTエンドポイントを持っている私は、ミリ秒、秒の両方としてパス変数を渡して試してみました。しかし、私は次の例外に両方の方法を取得:
"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"
誰かが、私は(どちらか秒またはミリ秒)に渡すことができる方法を説明し、そのような1446361200などの文字列と、それはZonedDateTimeに変換するために取得していただけますか?
または、文字列として渡してから変換を実行する唯一の方法はありますか?もしそうなら、同様のデザインを持つ複数のメソッドに対してこれを扱う一般的な方法はありますか?
'ZonedDateTime'は比較的新しく、Springはそれを直接サポートするように更新されていない可能性があります。これを回避する方法については、JasonZの回答を参照してください。 – Powerlord