-
Notifications
You must be signed in to change notification settings - Fork 38.4k
Spring Boot WebFlux validation of invalid inputs #31045
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
Comments
I can indeed reproduce with the repro provided with WebFlux but not with WebMVC. With WebMvc, With WebFlux, As far as I can tell, it does not look like Kotlin specific. |
When I've used Java POJO instead of Kotlin Data class, it works well and returns 400 instead of crashing with 500, so it related to Kotlin data class, which quite bit different to POJO. @RestController
@RequestMapping("/sample")
class SampleController {
data class Arguments(val intValue: Int) {
class Pojo{
var intValue: Int = -1
fun toData() = Arguments(intValue = this.intValue)
}
}
@GetMapping("/echo")
fun resource(args: Arguments.Pojo) = "Return back: ${args.toData().intValue}"
} |
If the class have a single default constructor, then |
Adapt spring-projectsgh-31045 fix to the main branch, and throw a WebExchangeBindException instead of a ServerWebInputException.
I am building java application using Spring Boot 2.7.12
And I have very simpler REST API controller like that:
And the issue when I am making a regular regular request as expected, everything works fine:
$ curl http://localhost:8080/sample/echo?intValue=111 Return back: 111
However if I will enter non-numeric value, Spring Boot is crashing:
If it is non-valid input, it should rather be 400 Bad Requests, than 500 Internal errors, and such things should be handled by the framework.
We using the Spring Boot framework, because we need some framework that will handle all edge case scenarios with mapping of the HTTP request parameters to controller input arguments, and that obviously should be handled properly by the framework.
Could you please advise, how to handle such HTTP requests properly?
Steps to reproduce
Download attach sample project: demo.zip
Run following command:
Listing output:
Stack trace: log.txt
The text was updated successfully, but these errors were encountered: