Skip to content

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

@flezsoftware

Description

@flezsoftware

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)

Metadata

Metadata

Assignees

Labels

status: backportedAn issue that has been backported to maintenance branchestype: documentationA documentation task

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions