-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@ApiParam annotation NumberFormatException bug #2979
Comments
I also encountered the same problem, I found that swagger-models-1.5.21.jar has solved this problem, like this @JsonProperty("x-example")
public Object getExample() {
if (example == null || example.isEmpty()) {
return example;
}
....
} So you can exclude the 1.5.20 version of the jar and import the 1.5.21 version of the jar, like this <dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
<exclusions>
<exclusion>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
<version>1.5.21</version>
</dependency> But I have not tried this method because I don't know if there will be version compatibility issues. So I fork this code and modify this line of code to compile it. I think you can do the same to solve the problem. |
See springfox/springfox#2265 for more info. |
See: swagger-api/swagger-core#2979 and springfox/springfox#2265 Upgrading to swagger-models 1.5.21 is the long term fix.
when i use @ApiParam with an int param but without use example .
like that :
@ApiParam(value = "1 ios 2 android") Integer channel
it will thorw NumberFormatException
java.lang.NumberFormatException: For input string: "" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Long.parseLong(Long.java:601) at java.lang.Long.valueOf(Long.java:803) at io.swagger.models.parameters.AbstractSerializableParameter.getExample(AbstractSerializableParameter.java:412) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
i saw the source code is
`
@JsonProperty("x-example")
public Object getExample() {
if (this.example == null) {
return null;
} else {
try {
if ("integer".equals(this.type)) {
return Long.valueOf(this.example);
}
and the default example value is "" .
public @interface ApiParam {
boolean required() default false;
String example() default "";
}
`
should it return 0 when the param type is int ?
The text was updated successfully, but these errors were encountered: