Java Swagger Number format exception

By | 2019년 11월 1일

Swagger 적용 후 Swagger 페이지를 열면 아래와 같은 오류를 만날때가 있다.

java.lang.NumberFormatException: For input string: ""
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[?:1.8.0_202]
    at java.lang.Long.parseLong(Long.java:601) ~[?:1.8.0_202]
    at java.lang.Long.valueOf(Long.java:803) ~[?:1.8.0_202]
    at io.swagger.models.parameters.AbstractSerializableParameter.getExample(AbstractSerializableParameter.java:412) [swagger-models-1.5.20.jar:1.5.20]
    at sun.reflect.GeneratedMethodAccessor112.invoke(Unknown Source) ~[?:?]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_202]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_202]
    at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:687) [jackson-databind-2.9.7.jar:2.9.7]
    at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:719) [jackson-databind-2.9.7.jar:2.9.7]

해결 방법은 swagger-annotations과 swagger-models 를 이전 버전을 사용하는 방법이다.

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // swagger
    compile(group: 'io.springfox', name: 'springfox-swagger2', version: '2.9.2') {
        exclude module: 'swagger-annotations' exclude module: 'swagger-models'
    }
    compile("io.swagger:swagger-annotations:1.5.21")
    compile("io.swagger:swagger-models:1.5.21")
    compile(group: 'io.springfox', name: 'springfox-swagger-ui', version: '2.9.2')
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

2 thoughts on “Java Swagger Number format exception

  1. Solomon

    What’s an example @apimodel property that causes this issue? Can we developers fix up our annotations to silence this? I checked all of mine on Integer and Long type, all have an example value that’s a valid number, yet the warning messages still appear in my app’s log.

Comments are closed.