BackEnd
[kotlin + swagger-ui] java.lang.NumberFormatException: For input string: "" 에러 해결
mingg123
2023. 10. 22. 22:26
현상
- http://localhost:8080/swagger-ui/index.html# 에 접속하면 NumberFormatException 에러를 뱉었다. (평소엔 괜찮았음)
원인
- 평소엔 이상이 없었는데 최근부터 발생해서 최근 커밋 내용을 뒤져보았다.
- 추가한 부분은 Swagger-ui에 @ApiOperation, @ApiImplicitParam을 추가했었다.
- 원인은 @ApiImplicitParam 에서 숫자타입을 사용시 'example'를 작성해주지 않아서 이다.
@GetMapping("/detail")
@ApiOperation(value = "상품 상세 정보", notes = "상품 상세 정보를 반환 합니다")
@ApiImplicitParam(name = "id", value = "조회할 상품 ID", required = true)
fun getProduct(@RequestParam("id") id: Long): ResponseEntity<ProductDetailDTO> {
return ResponseEntity.ok(productService.getProductDetail(id))
}
해결
- @ApiImplicitParam 사용시 example 을 추가해주었다. (아래와 같이 작성)
@GetMapping("/detail")
@ApiOperation(value = "상품 상세 정보", notes = "상품 상세 정보를 반환 합니다")
@ApiImplicitParam(name = "id", value = "조회할 상품 ID", required = true, example="1")
fun getProduct(@RequestParam("id") id: Long): ResponseEntity<ProductDetailDTO> {
return ResponseEntity.ok(productService.getProductDetail(id))
}
swagger-ui 사용시에도 에러가 발생하지 않았다!
몰랐던 부분을 알게되었다. 굳