Если вы хотите получить параметр в качестве даты, тогда нужно определить шаблон.Попробуйте с этим:
@GetMapping("/findWithRange")
public ResponseEntity<List<Appointment>> findAllWithCreationRange(@RequestParam("start") @DateTimeFormat(pattern = "yyyy-MM-dd") Date start, @RequestParam("end") @DateTimeFormat(pattern = "yyyy-MM-dd") Date end) {
List<Appointment> appointments = service.findAllWithCreationRange(start, end);
if (Objects.isNull(appointments)) {
ResponseEntity.badRequest().build();
}
return ResponseEntity.ok(appointments);
}
Если вы хотите получить sql.Date, то необходимо использовать пользовательский десериализатор.Попробуйте это:
@GetMapping("/findWithRange")
public ResponseEntity<List<Appointment>> findAllWithCreationRange(@RequestParam("start") @JsonDeserialize(using = SqlDateConverter.class) Date start, @RequestParam("end") @JsonDeserialize(using = SqlDateConverter.class) Date end) {
List<Appointment> appointments = service.findAllWithCreationRange(start, end);
if (Objects.isNull(appointments)) {
ResponseEntity.badRequest().build();
}
return ResponseEntity.ok(appointments);
}
Sql конвертер даты:
public class SqlDateConverter extends JsonDeserializer<Date> {
@Override
public Date deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
return Date.valueOf(p.getText());
}
}
Если вы хотите десериализовать sql.Date глобально, попробуйте добавить только этот компонент:
@Bean
public Jackson2ObjectMapperBuilder configureObjectMapper() {
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
ObjectMapper objectMapper = new ObjectMapper();
SimpleModule module = new SimpleModule();
module.addDeserializer(Date.class,new SqlDateConverter());
objectMapper.registerModule(module);
builder.configure(objectMapper);
return builder;
}