Skip to content

Commit 59e4755

Browse files
committed
Correct WebFlux docs on BindingResult with @RequestBody
Backport of 70a0c93 Closes spring-projectsgh-22997
1 parent 2576aa4 commit 59e4755

File tree

1 file changed

+17
-25
lines changed

1 file changed

+17
-25
lines changed

src/docs/asciidoc/web/webflux.adoc

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,9 +1661,8 @@ and others) and is equivalent to `required=false`.
16611661
See "`Any other argument`" later in this table.
16621662

16631663
| `Errors`, `BindingResult`
1664-
| For access to errors from validation and data binding for a command object
1665-
(that is, a `@ModelAttribute` argument) or errors from the validation of a `@RequestBody` or
1666-
`@RequestPart` argument. An `Errors`, or `BindingResult` argument must be declared
1664+
| For access to errors from validation and data binding for a command object, i.e. a
1665+
`@ModelAttribute` argument. An `Errors`, or `BindingResult` argument must be declared
16671666
immediately after the validated method argument.
16681667

16691668
| `SessionStatus` + class-level `@SessionAttributes`
@@ -2318,24 +2317,19 @@ you can declare a concrete target `Object`, instead of `Part`, as the following
23182317
<1> Using `@RequestPart` to get the metadata.
23192318
====
23202319

2321-
You can use `@RequestPart` combination with `javax.validation.Valid` or Spring's
2322-
`@Validated` annotation, which causes Standard Bean Validation to be applied.
2323-
By default, validation errors cause a `WebExchangeBindException`, which is turned
2324-
into a 400 (`BAD_REQUEST`) response. Alternatively, you can handle validation errors locally
2325-
within the controller through an `Errors` or `BindingResult` argument, as the following example shows:
2320+
You can use `@RequestPart` in combination with `javax.validation.Valid` or Spring's
2321+
`@Validated` annotation, which causes Standard Bean Validation to be applied. Validation
2322+
errors lead to a `WebExchangeBindException` that results in a 400 (BAD_REQUEST) response.
2323+
The exception contains a `BindingResult` with the error details and can also be handled
2324+
in the controller method by declaring the argument with an async wrapper and then using
2325+
error related operators:
23262326

23272327
====
23282328
[source,java,indent=0]
23292329
[subs="verbatim,quotes"]
23302330
----
2331-
@PostMapping("/")
2332-
public String handle(@Valid @RequestPart("meta-data") MetaData metadata, <1>
2333-
BindingResult result) { <2>
2334-
// ...
2335-
}
2336-
----
2337-
<1> Using a `@Valid` annotation.
2338-
<2> Using a `BindingResult` argument.
2331+
public String handle(@Valid @RequestPart("meta-data") Mono<MetaData> metadata) {
2332+
// use one of the onError* operators...
23392333
====
23402334

23412335
To access all multipart data as a `MultiValueMap`, you can use `@RequestBody`,
@@ -2407,20 +2401,18 @@ You can use the <<webflux-config-message-codecs>> option of the <<webflux-config
24072401
configure or customize message readers.
24082402

24092403
You can use `@RequestBody` in combination with `javax.validation.Valid` or Spring's
2410-
`@Validated` annotation, which causes Standard Bean Validation to be applied.
2411-
By default, validation errors cause a `WebExchangeBindException`, which is turned
2412-
into a 400 (`BAD_REQUEST`) response. Alternatively, you can handle validation errors locally
2413-
within the controller through an `Errors` or a `BindingResult` argument. The following
2414-
example uses a `BindingResult` argument`:
2404+
`@Validated` annotation, which causes Standard Bean Validation to be applied. Validation
2405+
errors cause a `WebExchangeBindException`, which results in a 400 (BAD_REQUEST) response.
2406+
The exception contains a `BindingResult` with error details and can be handled in the
2407+
controller method by declaring the argument with an async wrapper and then using error
2408+
related operators:
24152409

24162410
====
24172411
[source,java,indent=0]
24182412
[subs="verbatim,quotes"]
24192413
----
2420-
@PostMapping("/accounts")
2421-
public void handle(@Valid @RequestBody Account account, BindingResult result) {
2422-
// ...
2423-
}
2414+
public void handle(@Valid @RequestBody Mono<Account> account) {
2415+
// use one of the onError* operators...
24242416
----
24252417
====
24262418

0 commit comments

Comments
 (0)