diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java index d87290ec1e4..4ac5a107aa6 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClient.java @@ -781,71 +781,86 @@ public interface WebClient { Function> exceptionFunction); /** - * Extract the body to a {@code Mono}. By default, if the response has status code 4xx or - * 5xx, the {@code Mono} will contain a {@link WebClientException}. This can be overridden - * with {@link #onStatus(Predicate, Function)}. - * @param elementClass the expected response body element class - * @param response body type - * @return a mono containing the body, or a {@link WebClientResponseException} if the - * status code is 4xx or 5xx + * Decode the body to the given target type. For an error response (status + * code of 4xx or 5xx), the {@code Mono} emits a {@link WebClientException}. + * Use {@link #onStatus(Predicate, Function)} to customize error response + * handling. + * @param elementClass the type to decode to + * @param the target body type + * @return the decoded body */ Mono bodyToMono(Class elementClass); /** - * Extract the body to a {@code Mono}. By default, if the response has status code 4xx or - * 5xx, the {@code Mono} will contain a {@link WebClientException}. This can be overridden - * with {@link #onStatus(Predicate, Function)}. - * @param elementTypeRef a type reference describing the expected response body element type - * @param response body type - * @return a mono containing the body, or a {@link WebClientResponseException} if the - * status code is 4xx or 5xx + * Variant of {@link #bodyToMono(Class)} with a {@link ParameterizedTypeReference}. + * @param elementTypeRef the type to decode to + * @param the target body type + * @return the decoded body */ Mono bodyToMono(ParameterizedTypeReference elementTypeRef); /** - * Extract the body to a {@code Flux}. By default, if the response has status code 4xx or - * 5xx, the {@code Flux} will contain a {@link WebClientException}. This can be overridden - * with {@link #onStatus(Predicate, Function)}. - * @param elementClass the class of elements in the response - * @param the type of elements in the response - * @return a flux containing the body, or a {@link WebClientResponseException} if the - * status code is 4xx or 5xx + * Decode the body to a {@link Flux} with elements of the given type. + * For an error response (status code of 4xx or 5xx), the {@code Mono} + * emits a {@link WebClientException}. Use {@link #onStatus(Predicate, Function)} + * to customize error response handling. + * @param elementClass the type of element to decode to + * @param the body element type + * @return the decoded body */ Flux bodyToFlux(Class elementClass); /** - * Extract the body to a {@code Flux}. By default, if the response has status code 4xx or - * 5xx, the {@code Flux} will contain a {@link WebClientException}. This can be overridden - * with {@link #onStatus(Predicate, Function)}. - * @param elementTypeRef a type reference describing the expected response body element type - * @param the type of elements in the response - * @return a flux containing the body, or a {@link WebClientResponseException} if the - * status code is 4xx or 5xx + * Variant of {@link #bodyToMono(Class)} with a {@link ParameterizedTypeReference}. + * @param elementTypeRef the type of element to decode to + * @param the body element type + * @return the decoded body */ Flux bodyToFlux(ParameterizedTypeReference elementTypeRef); /** - * Return the response as a delayed {@code ResponseEntity}. By default, if the response has - * status code 4xx or 5xx, the {@code Mono} will contain a {@link WebClientException}. This - * can be overridden with {@link #onStatus(Predicate, Function)}. + * Return a {@code ResponseEntity} with the body decoded to an Object of + * the given type. For an error response (status code of 4xx or 5xx), the + * {@code Mono} emits a {@link WebClientException}. Use + * {@link #onStatus(Predicate, Function)} to customize error response handling. * @param bodyClass the expected response body type * @param response body type - * @return {@code Mono} with the {@code ResponseEntity} + * @return the {@code ResponseEntity} with the decoded body * @since 5.2 */ Mono> toEntity(Class bodyClass); /** - * Return the response as a delayed {@code ResponseEntity}. By default, if the response has - * status code 4xx or 5xx, the {@code Mono} will contain a {@link WebClientException}. This - * can be overridden with {@link #onStatus(Predicate, Function)}. - * @param bodyTypeReference a type reference describing the expected response body type - * @param response body type - * @return {@code Mono} with the {@code ResponseEntity} + * Variant of {@link #bodyToMono(Class)} with a {@link ParameterizedTypeReference}. + * @param bodyTypeReference the expected response body type + * @param the response body type + * @return the {@code ResponseEntity} with the decoded body * @since 5.2 */ Mono> toEntity(ParameterizedTypeReference bodyTypeReference); + /** + * Return a {@code ResponseEntity} with the body decoded to a {@code List} + * of elements of the given type. For an error response (status code of + * 4xx or 5xx), the {@code Mono} emits a {@link WebClientException}. + * Use {@link #onStatus(Predicate, Function)} to customize error response + * handling. + * @param elementClass the type of element to decode the target Flux to + * @param the body element type + * @return the {@code ResponseEntity} + * @since 5.2 + */ + Mono>> toEntityList(Class elementClass); + + /** + * Variant of {@link #toEntity(Class)} with a {@link ParameterizedTypeReference}. + * @param elementTypeRef the type of element to decode the target Flux to + * @param the body element type + * @return the {@code ResponseEntity} + * @since 5.2 + */ + Mono>> toEntityList(ParameterizedTypeReference elementTypeRef); + /** * Return a {@code ResponseEntity} with the body decoded to a {@code Flux} * of elements of the given type. For an error response (status code of @@ -856,7 +871,7 @@ public interface WebClient { * be subscribed to or else associated resources will not be released. * @param elementType the type of element to decode the target Flux to * @param the body element type - * @return the resulting {@code ResponseEntity} + * @return the {@code ResponseEntity} * @since 5.3.1 */ Mono>> toEntityFlux(Class elementType); @@ -865,43 +880,17 @@ public interface WebClient { * Variant of {@link #toEntity(Class)} with a {@link ParameterizedTypeReference}. * @param elementTypeReference the type of element to decode the target Flux to * @param the body element type - * @return the resulting {@code ResponseEntity} + * @return the {@code ResponseEntity} * @since 5.3.1 */ Mono>> toEntityFlux(ParameterizedTypeReference elementTypeReference); /** - * Return the response as a delayed list of {@code ResponseEntity}s. By default, if the - * response has status code 4xx or 5xx, the {@code Mono} will contain a - * {@link WebClientException}. This can be overridden with - * {@link #onStatus(Predicate, Function)}. - * @param elementClass the expected response body list element class - * @param the type of elements in the list - * @return {@code Mono} with the list of {@code ResponseEntity}s - * @since 5.2 - */ - Mono>> toEntityList(Class elementClass); - - /** - * Return the response as a delayed list of {@code ResponseEntity}s. By default, if the - * response has status code 4xx or 5xx, the {@code Mono} will contain a - * {@link WebClientException}. This can be overridden with - * {@link #onStatus(Predicate, Function)}. - * @param elementTypeRef the expected response body list element reference type - * @param the type of elements in the list - * @return {@code Mono} with the list of {@code ResponseEntity}s - * @since 5.2 - */ - Mono>> toEntityList(ParameterizedTypeReference elementTypeRef); - - /** - * Return the response as a delayed {@code ResponseEntity} containing status and headers, - * but no body. By default, if the response has status code 4xx or 5xx, the {@code Mono} - * will contain a {@link WebClientException}. This can be overridden with - * {@link #onStatus(Predicate, Function)}. - * Calling this method will {@linkplain ClientResponse#releaseBody() release} the body of - * the response. - * @return {@code Mono} with the bodiless {@code ResponseEntity} + * Return a {@code ResponseEntity} without a body. For an error response + * (status code of 4xx or 5xx), the {@code Mono} emits a + * {@link WebClientException}. Use {@link #onStatus(Predicate, Function)} + * to customize error response handling. + * @return the {@code ResponseEntity} * @since 5.2 */ Mono> toBodilessEntity();