PythonQQ :
I'm trying to get an ISO String with @RequestParam and parse it to a Date.
Using code below, I tried to test with http://localhost:8989/api/v1/test?date=2019-08-19%2000:00:00.000+0000
But the result was 400 Bad Request, When I changed the type of date value to String, it was 2019-08-19 00:00:00.000 0000
.
public class myController {
@GetMapping(value = "/api/{version}/test", produces = "application/json")
public ResponseEntity<MyList> getFreeList(
@PathVariable
String version,
@RequestParam("date")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSSZ")
Optional<Date> date) {
return new ResponseEntity<>(myService.getList(
date.orElse(null)),
HttpStatus.OK);
}
}
I can't change the URL format. How to get the plus sign properly?
Eyal :
Url parameters must be encoded
It's the caller's responsibility to do so. If the caller uses Java, he can simply set the value to be:
URLEncoder.encode("2019-08-19 000:00:00.000+0000", "UTF-8");
Which will be resolved to
2019-08-19%2000:00:00.000%2B0000