我使用的是swagger-jaxrs_2.10.0版本1.2.3(刚刚从1.2.2升级,结果相同)
如果我有这样的课程:
public class XXXResponse
{
private List<Boolean> booleans;
private List<Byte> bytes;
private List<Short> shorts;
private List<Integer> integers;
private List<Long> longs;
private List<Float> floats;
private List<Double> doubles;
private List<String> strings;
private List<Date> dates;
// set/get methods
}
Swagger将其报告为:
{
"integers": [
"int"
],
"bytes": [
"any"
],
"longs": [
"any"
],
"dates": [
"any"
],
"shorts": [
"any"
],
"strings": [
"string"
],
"doubles": [
"any"
],
"floats": [
"any"
],
"booleans": [
"boolean"
]
}
我需要具备什么特殊的魔力才能使“任何”变成适当的类型?
答案 0 :(得分:1)
事实证明,配置杰克逊可以解决问题:
@Provider
@Produces(MediaType.APPLICATION_JSON)
public class JacksonJsonProvider extends JacksonJaxbJsonProvider
{
private static ObjectMapper commonMapper = null;
public JacksonJsonProvider()
{
if(commonMapper == null)
{
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
commonMapper = mapper;
}
super.setMapper(commonMapper);
}
}