Skip to content
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

WebFlux documentation states incorrectly that BindingResult is supported after @RequestBody #22997

Closed
flezsoftware opened this issue May 20, 2019 · 2 comments
Assignees
Labels
status: backported An issue that has been backported to maintenance branches type: documentation A documentation task
Milestone

Comments

@flezsoftware
Copy link

flezsoftware commented May 20, 2019

According to Webflux documentation:
https://github.com/spring-projects/spring-framework/blob/master/src/docs/asciidoc/web/webflux.adoc

You can use @RequestBody in combination with javax.validation.Valid or Spring’s @Validated annotation, which causes Standard Bean Validation to be applied. By default, validation errors cause a WebExchangeBindException, which is turned into a 400 (BAD_REQUEST) response. Alternatively, you can handle validation errors locally within the controller through an Errors or a BindingResult argument.

The following example uses a BindingResult argument:

@PostMapping("/accounts")
public void handle(@Valid @RequestBody Account account, BindingResult result) {
	// ...
}

This part throws an following exception :

java.lang.IllegalStateException: An Errors/BindingResult argument is expected immediately after the @ModelAttribute argument to which it applies. For @RequestBody and @RequestPart arguments, please declare them with a reactive type wrapper and use its onError operators to handle WebExchangeBindException

Sample code :
https://github.com/flezsoftware/requestbody-bindingresult

Suggested changes to documentation :
https://github.com/spring-projects/spring-framework/pull/22993/files

and comment by @rstoyanchev #22993 (comment)

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label May 20, 2019
@rstoyanchev
Copy link
Contributor

I've edited your comment to improve the formatting. You might want to check out this Mastering Markdown guide for future reference.

@rstoyanchev rstoyanchev added type: documentation A documentation task and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Dec 5, 2019
@rstoyanchev rstoyanchev self-assigned this Dec 5, 2019
@rstoyanchev rstoyanchev added this to the 5.2.3 milestone Dec 5, 2019
@rstoyanchev
Copy link
Contributor

@flezsoftware, thanks for the sample and my apologies for not seeing this sooner. To my surprise, you are correct that BindingResult isn't supported with @RequestBody on WebFlux. It's something we should correct but we can correct the documentation to start.

@rstoyanchev rstoyanchev changed the title @RequestBody and BindingResult error from Webflux documentation WebFlux documentation states incorrectly that BindingResult is supported after @RequestBody Dec 5, 2019
@spring-projects-issues spring-projects-issues added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-5.1.x labels Dec 10, 2019
rstoyanchev added a commit that referenced this issue Dec 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: backported An issue that has been backported to maintenance branches type: documentation A documentation task
Projects
None yet
Development

No branches or pull requests

3 participants