Swagger异常:NumberFormatException: For input string: “”

报错详情:

java.lang.NumberFormatException: For input string: ""
     at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[na:1.8.0_191]
     at java.lang.Long.parseLong(Long.java:601) ~[na:1.8.0_191]
     at java.lang.Long.valueOf(Long.java:803) ~[na:1.8.0_191]
     at io.swagger.models.parameters.AbstractSerializableParameter.getExample(AbstractSerializableParameter.java:412)
	 ...

报错原因:
该异常出现于springfox-swagger22.9.2版本,在对@ApiModelProperty注解进行处理时,对于example属性存在要求。如使用@ApiModelProperty的字段为Integer,则需要标注为@ApiModelProperty(example = "100"),若无example标注,则会默认为空字符串 "",所以引发字符串转数字的异常。

此异常属于swagger-models的Bug,在1.5.21版本进行了修复。由于springfox-swagger22.9.2版本依赖的是swagger-models1.5.20版本,所以出现该异常。

解决方法:

1.将springfox-swagger2中的swagger-models进行移除,并自行添加该依赖。

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
            <exclusions>
                <exclusion>
                    <artifactId>swagger-models</artifactId>
                    <groupId>io.swagger</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <!--1.5.21版本及以上均可 但建议只提升至1.5.21-->
        <!--若要提高至高版本,需同时对swagger-annotations进行移除和手动添加,以防止不兼容-->
        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-models</artifactId>
            <version>1.5.21</version>
            <scope>compile</scope>
        </dependency>

2.将pom文件中的springfox-swagger2版本进行修改,2.9.2版本出错,降为2.8.0即可。

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.8.0</version>
        </dependency>
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值