Swagger2.9.2 into the API interface reported a NumberFormatException

[ Reproduced please specify ]:

Original Source : https://www.cnblogs.com/jstarseven/p/11778377.html      Author : jstarseven     codeword very hard .....  


  

Problems found

Swagger2.9.2 version, swagger when accessing the home page, the console error.

 1 WARN 19699 --- [nio-1111-exec-4] i.s.m.p.AbstractSerializableParameter    : Illegal DefaultValue null for parameter type integer
 2 
 3 java.lang.NumberFormatException: For input string: ""
 4     at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[na:1.8.0_171]
 5     at java.lang.Long.parseLong(Long.java:601) ~[na:1.8.0_171]
 6     at java.lang.Long.valueOf(Long.java:803) ~[na:1.8.0_171]
 7     at io.swagger.models.parameters.AbstractSerializableParameter.getExample(AbstractSerializableParameter.java:412) ~[swagger-models-1.5.20.jar:1.5.20]
 8     at sun.reflect.GeneratedMethodAccessor109.invoke(Unknown Source) ~[na:na]
 9     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_171]
10     at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_171]
11     at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:687) [jackson-databind-2.9.6.jar:2.9.6]

problem causes

See swagger2.9.2 source swagger-models-1.5.20.jar in io.swagger.models.parameters.AbstractSerializableParameter, found to be due to the use @ApiModelProperty, example no assignment entity class property caused will getExample method of AbstractSerializableParameter the example of converting the return value class attribute values, the default value example is "", so when the assignment is not example, the above abnormality occurs.

swagger-models-1.5.20 source code:

 

 

Four ways to solve the problem:

First, the law hard to get rich: the @ApiModelProperty on each type of example are assigned numeric string of numbers, which also tired of it!

  

Second, self-deceiving law: Modify springboot output log, the log file is set to level io.swagger.models.parameters.AbstractSerializableParameter error , which is too self-deception of it!

  

Third, inquisitive law : 1.5.20 code is not out of the question, I have changed, re-make a package, not on the thing! 666 Old iron, big brother on you!

 

Fourth, the lazy mode method: find swagger-models-1.5.22 in solving this problem, then I direct import cover, would not Miya, ha ha ha! One second maxed, continue to develop, nice!

 swagger-models-1.5.22 source code:

  replace:

 

   


 -END-

Guess you like

Origin www.cnblogs.com/jstarseven/p/11778377.html