【问题标题】:Correct data type with Swagger/Springfox when property has @XmlJavaTypeAdapter annotation当属性具有 @XmlJavaTypeAdapter 注释时,使用 Swagger/Springfox 更正数据类型
【发布时间】:2020-04-29 18:55:33
【问题描述】:
我已经用 swagger 注释对端点进行了注释。在@ResponseHeader 中,我将返回类设置为响应。此类包含一个使用@XmlJavaTypeAdapter 注释的属性。适配器正在更改属性的数据类型。不幸的是,Swagger 显示了属性的类型,而不是 Adapter 的返回类型。可以这样做吗?
我已经尝试过使用@ApiModelProperty() 对属性进行注释。但我无法将 dataType 设置为 List(原始数据类型或只是一个列表有效)。
谢谢:)
【问题讨论】:
标签:
java
spring
jaxb
swagger
springfox
【解决方案1】:
以下操作无效:
@ApiModelProperty(dataType = "List<Map<String, String>>")
public Map<String, String> someMap = new HashMap<>();
我必须创建一个接口
public interface ListOfMap extends List<Map<String, String>> {}
然后我在ApiModelProperty中使用了这个接口:
@ApiModelProperty(dataType = "ListOfMap")
public Map<String, String> someMap = new HashMap<>();
有了这个,一切正常:)