使用swagger的时候,用 @ApiModelProperty 修饰的类的属性如果没设置的话默认赋值为"",当Integer类型的属性没设置example的话就会报错
错误设置:
java
@ApiModelProperty(value = "设备id")
private Integer typeId;
java
Illegal DefaultValue null for parameter type integer
java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) ~[na:1.8.0_391]
at java.lang.Long.parseLong(Long.java:601) ~[na:1.8.0_391]
at java.lang.Long.valueOf(Long.java:803) ~[na:1.8.0_391]
at io.swagger.models.parameters.AbstractSerializableParameter.getExample(AbstractSerializableParameter.java:412) ~[swagger-models-1.5.20.jar:1.5.20]
at sun.reflect.GeneratedMethodAccessor130.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_391]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_391]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:688) [jackson-databind-2.9.8.jar:2.9.8]
正确设置:
java
@ApiModelProperty(value = "设备id",example = "1")
private Integer typeId;