swagger2.9.2 报错 For input string: “” 解决方法
作者:互联网
swagger2.9.2 报错 For input string: “” 解决方法
报错信息:
java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[na:1.8.0_171]
at java.lang.Long.parseLong(Long.java:601) ~[na:1.8.0_171]
at java.lang.Long.valueOf(Long.java:803) ~[na:1.8.0_171]
at io.swagger.models.parameters.AbstractSerializableParameter.getExample(AbstractSerializableParameter.java:412) ~[swagger-models-1.5.20.jar:1.5.20]
at sun.reflect.GeneratedMethodAccessor109.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_171]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_171]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:687) [jackson-databind-2.9.6.jar:2.9.6]
这是因为Swagger2中 @ApiModelProperties 注解不指定example的值产生的报错,会默认为"",swagger在后续处理的时候强行转化空字符串就会抛出异常。这也是Swagger2的bug。
处理方式:
将swagger的 annotations以及models 替换为1.5.21版本即可
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.21</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
<version>1.5.21</version>
</dependency>
参考文章链接:https://my.oschina.net/wuaiting/blog/4286444
标签:1.5,java,string,swagger2.9,na,1.8,报错,swagger,171 来源: https://blog.csdn.net/weixin_45630446/article/details/115824063