Java 8 LocalDate 大摇大摆地显示
Java 8 LocalDate displaying in swagger
我有一个 DTO,其中包含 Java 8 LocalDate 类型的字段。使用 Jackson 注释可以将格式设置为 ISO.DATE
并且一切正常。但是 Swagger(我有版本 2.+)将 LocalDate.class
视为对象
LocalDate {
month (integer, optional),
year (integer, optional)
}
(这是真的,但是...)我想将其作为与 util.Date
一起使用的格式的字符串来表示。
我该如何解决?
我遇到了同样的问题,所以我添加了
@Bean
public Docket docket() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("name")
.directModelSubstitute(LocalDateTime.class, String.class)
.directModelSubstitute(LocalDate.class, String.class)
.directModelSubstitute(LocalTime.class, String.class)
.directModelSubstitute(ZonedDateTime.class, String.class)
.apiInfo(apiInfo())
.select()
.paths(paths())
.build();
}
在摘要配置中。
directModelSubstitute
大摇大摆地把 LocalDate
当作 String
class
我有一个 DTO,其中包含 Java 8 LocalDate 类型的字段。使用 Jackson 注释可以将格式设置为 ISO.DATE
并且一切正常。但是 Swagger(我有版本 2.+)将 LocalDate.class
视为对象
LocalDate {
month (integer, optional),
year (integer, optional)
}
(这是真的,但是...)我想将其作为与 util.Date
一起使用的格式的字符串来表示。
我该如何解决?
我遇到了同样的问题,所以我添加了
@Bean
public Docket docket() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("name")
.directModelSubstitute(LocalDateTime.class, String.class)
.directModelSubstitute(LocalDate.class, String.class)
.directModelSubstitute(LocalTime.class, String.class)
.directModelSubstitute(ZonedDateTime.class, String.class)
.apiInfo(apiInfo())
.select()
.paths(paths())
.build();
}
在摘要配置中。
directModelSubstitute
大摇大摆地把 LocalDate
当作 String
class