Swagger2异常:Illegal DefaultValue null for parameter type integer || For input string: “”

Swagger2异常:Illegal DefaultValue null for parameter type integer

异常分析

Illegal DefaultValue null for parameter type integer

NumberFormatException: For input string: “”

从上面这句可以看出,有个默认值是空字符串的变量转换成Integer类型时异常。

img

根据上面这句报错信息,点进去AbstractSerializableParameter.java:412可以看到

if(BaseIntegerProperty.TYPE.equals(type)){

return Long.valueOf(example);

}

就是说如果实体属性类型是Integer,就把example转为Long类型,而example默认为"",导致转换错误。

解决办法:两种

添加example默认值

每个使用@ApiModelProperty注解的Interger类型的参数都需要加上example的默认数值,但这种修改方式只能说相当麻烦

@ApiModelProperty(value = "num",example = "1")
private Integer num;

如果每个值都需要添加,那么会很多。

升级版本1.5.21+

1.5.21+都已经修复了这个问题了,升级

<!-- Swagger -->
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>${swagger.fox.version}</version>
    <!--移除swagger-models 1.5.20 依赖,存在Swagger2异常:Illegal DefaultValue null for parameter type integer问题-->
    <exclusions>
        <exclusion>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-annotations</artifactId>
        </exclusion>
        <exclusion>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-models</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<!-- Swagger -->
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
</dependency>

<dependency>
    <groupId>io.swagger</groupId>
    <artifactId>swagger-models</artifactId>
    <version>1.6.2</version>
</dependency>

<dependency>
    <groupId>io.swagger</groupId>
    <artifactId>swagger-annotations</artifactId>
    <version>1.6.2</version>
</dependency>
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

好奇新

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值