2016-11-10 1024 views
-1

我有一个DTO,其中包含Java 8 LocalDate类型的字段。使用杰克逊注释可以将格式设置为ISO.DATE,并且一切正常。但扬鞭(我有版本2 +)看到LocalDate.class为对象Java 8 LocalDate在swagger中显示

LocalDate { 
month (integer, optional), 
year (integer, optional) 
} 

(这是真的,但...)我想dipsay以此为字符串格式,因为它与util.Date工作。 我该如何解决它?

回答

0

我正面临同样的问题,所以我在案卷配置添加

@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使得招摇治疗LocalDateString

+0

请妥善缩进代码以防止滚动 –