This question is very similar to this SO problem which is for older Date
API.
I want to achieve the same with Java 8 LocalDateTime
API. When I do,
@RequestMapping("/locationSnapshot/{userId}/{pointInTime}")
public MyResponse getLocationInTime(
@PathParam(value="userId") Long userId,
@PathParam(value="pointInTime")
@DateTimeFormat(pattern="yyyy-MM-dd'T'HH:mm:ss") LocalDateTime pointInTime) {
MyResponse response = new MyResponse();
return response;
}
I get,
Failed to instantiate [java.time.LocalDateTime]: No default constructor
found; nested exception is java.lang.NoSuchMethodException:
java.time.LocalDateTime.<init>()
Use @PathVariable instead of @PathParam
@RequestMapping("/locationSnapshot/{userId}/{pointInTime}")
public MyResponse getLocationInTime(
@PathVariable(value="userId") Long userId,
@PathVariable(value="pointInTime")
@DateTimeFormat(pattern="yyyy-MM-dd'T'HH:mm:ss") LocalDateTime pointInTime) {
MyResponse response = new MyResponse();
return response;
}
Try to add @RequestParam
before your pointInTime
parameter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With