Add toEntityFlux methods

Closes gh-26023
This commit is contained in:
Rossen Stoyanchev
2020-11-03 19:05:46 +00:00
parent 68934f1b79
commit 2e2d662158
3 changed files with 74 additions and 1 deletions

View File

@@ -622,6 +622,22 @@ class DefaultWebClient implements WebClient {
handleBodyFlux(response, response.bodyToFlux(elementTypeRef))));
}
@Override
public <T> Mono<ResponseEntity<Flux<T>>> toEntityFlux(Class<T> elementType) {
return this.responseMono.map(response ->
ResponseEntity.status(response.rawStatusCode())
.headers(response.headers().asHttpHeaders())
.body(response.bodyToFlux(elementType)));
}
@Override
public <T> Mono<ResponseEntity<Flux<T>>> toEntityFlux(ParameterizedTypeReference<T> elementTypeReference) {
return this.responseMono.map(response ->
ResponseEntity.status(response.rawStatusCode())
.headers(response.headers().asHttpHeaders())
.body(response.bodyToFlux(elementTypeReference)));
}
@Override
public Mono<ResponseEntity<Void>> toBodilessEntity() {
return this.responseMono.flatMap(response ->

View File

@@ -846,6 +846,30 @@ public interface WebClient {
*/
<T> Mono<ResponseEntity<T>> toEntity(ParameterizedTypeReference<T> bodyTypeReference);
/**
* 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
* 4xx or 5xx), the {@code Mono} emits a {@link WebClientException}.
* Use {@link #onStatus(Predicate, Function)} to customize error response
* handling.
* <p><strong>Note:</strong> The {@code Flux} representing the body must
* be subscribed to or else associated resources will not be released.
* @param elementType the type of element to decode the target Flux to
* @param <T> the body element type
* @return the resulting {@code ResponseEntity}
* @since 5.3.1
*/
<T> Mono<ResponseEntity<Flux<T>>> toEntityFlux(Class<T> elementType);
/**
* Variant of {@link #toEntity(Class)} with a {@link ParameterizedTypeReference}.
* @param elementTypeReference the type of element to decode the target Flux to
* @param <T> the body element type
* @return the resulting {@code ResponseEntity}
* @since 5.3.1
*/
<T> Mono<ResponseEntity<Flux<T>>> toEntityFlux(ParameterizedTypeReference<T> 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