Im my Spring Boot application, I have some controllers that accept a date as query parameter:
@RestController
public class MyController {
@GetMapping
public
This is currently not easily possible (e.g. by setting a simple configuration property), see #5523. The best solution I found so far is to register a Formatter
. This will also work with optional parameters modeled as Optional
:
@Bean
public Formatter localDateFormatter() {
return new Formatter() {
@Override
public LocalDate parse(String text, Locale locale) throws ParseException {
return LocalDate.parse(text, DateTimeFormatter.ISO_DATE);
}
@Override
public String print(LocalDate object, Locale locale) {
return DateTimeFormatter.ISO_DATE.format(object);
}
};
}
It may become possible to set this using a configuration property when my proposal in #9930 has been merged.