Swagger2 in Spring boot project causes an MethodArgumentTypeMismatchException by NumberFormatException
See original GitHub issueI use the swagger2 in my srping boot project,
here is my pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
</dependency>
and then my restful api :
@ApiOperation(value = "create some producer", notes = "create ....")
@ApiImplicitParam(name = "num", value = "number of producer", required = true, dataType = "Long")
@RequestMapping(value = "/producer/{num}", method = RequestMethod.POST)
public String postMultiNaaSProducer(@PathVariable Long num)
{
...
}
and then I get this error as below when I try the restful api in swagger ui:
{
"timestamp": 1489027913782,
"status": 400,
"error": "Bad Request",
"exception": "org.springframework.web.method.annotation.MethodArgumentTypeMismatchException",
"message": "Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: \"{num}\"",
"path": "/rocketmq/producer/%7Bnum%7D"
}
I don’t know why will it happened. And the api works well when I invoke by postman…
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Configuring Swagger2 with spring boot - java - Stack Overflow
Configuring Swagger2 with spring boot · I think, that problem will be in your path @RequestMapping(path="{/id}", method = RequestMethod.GET) , it ...
Read more >NumberFormatException: For input string: "" in Swagger ...
In my previous article about Documenting Spring Boot REST API with Swagger, ... NumberFormatException: For input string: "" at java.lang.
Read more >I can't run any version of swagger-fox. Spring Boot 2.4.2 + JDK 8.
Spring Boot 2.4.2 + JDK 8. I have previously added swagger-fox to my projects using the instruction below, but none fit.
Read more >Swagger,Knife4j java.lang.NumberFormatException
4. 5. Failed to convert value of type 'java.lang.String' to required type 'java.lang.Long'; nested exception is java.lang.NumberFormatException ...
Read more >Spring Boot + Swagger 2 Simple Hello World example
In this post we configure a spring boot application to integrate swagger2. Spring Boot example we had exposed a REST API . Documentation...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m sorry, I miss the
paramType="path"
in@ApiImplicitParam
annotation。It should be,
and it works well.
without
paramType
it consider the param num as a body param, so I only get the value of{num}
。Awesome! thanks for reporting back!