springdoc webflux自动转换String为java.time.LocalDate报错

Springdoc webflux automatically convert String to java.time.LocalDate error

当我使用 org.springdoc:springdoc-openapi-spring-boot-2-webflux:3.1.5 构建反应式时 api。

我收到以下错误:

Caused by: java.time.format.DateTimeParseException: Text '2021-03-24' could not be parsed at index 4

示例代码:

@RestController
public class Controller {
  @GetMapping(path = "/test")
  public Mono<String> test(@Valid TaskCriteria taskCriteria) {
    Mono.just("Subscribe completed, criteria: " + taskCriteria.toString());
  }
}
@Data
@AllArgsConstructor
@Schema(description = "Task matching criteria", name = "TaskCriteria")
@ParameterObject
public class TaskCriteria {

  @Parameter(description = "Date to run, using ISO-8601 format yyyy-MM-dd")
  @Schema(required = true, type = "string", format = "date", example = "2021-03-25")
  @NotNull
  private LocalDate date;

}

你的问题是你使用 @AllArgsConstructor 而不是 @NoArgsConstructor,jackson!

这是您的工作样本:

@RestController
public class HelloController {

    @GetMapping(path = "/test")
    public Mono<String> test(@Valid TaskCriteria taskCriteria) {
        return Mono.just("Subscribe completed, criteria: " + taskCriteria.toString());
    }

    @Data
    @NoArgsConstructor
    @Schema(description = "Task matching criteria", name = "TaskCriteria")
    @ParameterObject
    public class TaskCriteria {

        @Parameter(description = "Date to run, using ISO-8601 format yyyy-MM-dd")
        @Schema(required = true, type = "string", format = "date", example = "2021-03-25")
        @DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
        @NotNull
        private LocalDate date;

    }

}