Skip to content

Commit 729d0d2

Browse files
committed
Property handling of Void.class in WebClient retrieve()
Issue: SPR-16636
1 parent ab2410c commit 729d0d2

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,12 @@
4242
import org.springframework.http.HttpStatus;
4343
import org.springframework.http.MediaType;
4444
import org.springframework.http.client.reactive.ClientHttpRequest;
45-
import org.springframework.http.client.reactive.ClientHttpResponse;
4645
import org.springframework.lang.Nullable;
4746
import org.springframework.util.Assert;
4847
import org.springframework.util.CollectionUtils;
4948
import org.springframework.util.LinkedMultiValueMap;
5049
import org.springframework.util.MimeType;
5150
import org.springframework.util.MultiValueMap;
52-
import org.springframework.web.reactive.function.BodyExtractor;
5351
import org.springframework.web.reactive.function.BodyExtractors;
5452
import org.springframework.web.reactive.function.BodyInserter;
5553
import org.springframework.web.reactive.function.BodyInserters;
@@ -405,16 +403,17 @@ public ResponseSpec onStatus(Predicate<HttpStatus> statusPredicate,
405403
@Override
406404
@SuppressWarnings("unchecked")
407405
public <T> Mono<T> bodyToMono(Class<T> bodyType) {
406+
// Use bodyToMono (vs BodyExtractors) to ensure proper handling of Void.class...
408407
return this.responseMono.flatMap(
409-
response -> bodyToPublisher(response, BodyExtractors.toMono(bodyType),
408+
response -> bodyToPublisher(response, response.bodyToMono(bodyType),
410409
this::monoThrowableToMono));
411410
}
412411

413412
@Override
414413
@SuppressWarnings("unchecked")
415414
public <T> Mono<T> bodyToMono(ParameterizedTypeReference<T> typeReference) {
416415
return this.responseMono.flatMap(
417-
response -> bodyToPublisher(response, BodyExtractors.toMono(typeReference),
416+
response -> bodyToPublisher(response, response.bodyToMono(typeReference),
418417
this::monoThrowableToMono));
419418
}
420419

@@ -425,14 +424,14 @@ private <T> Mono<T> monoThrowableToMono(Mono<? extends Throwable> mono) {
425424
@Override
426425
public <T> Flux<T> bodyToFlux(Class<T> elementType) {
427426
return this.responseMono.flatMapMany(
428-
response -> bodyToPublisher(response, BodyExtractors.toFlux(elementType),
427+
response -> bodyToPublisher(response, response.bodyToFlux(elementType),
429428
this::monoThrowableToFlux));
430429
}
431430

432431
@Override
433432
public <T> Flux<T> bodyToFlux(ParameterizedTypeReference<T> typeReference) {
434433
return this.responseMono.flatMapMany(
435-
response -> bodyToPublisher(response, BodyExtractors.toFlux(typeReference),
434+
response -> bodyToPublisher(response, response.bodyToFlux(typeReference),
436435
this::monoThrowableToFlux));
437436
}
438437

@@ -441,15 +440,14 @@ private <T> Flux<T> monoThrowableToFlux(Mono<? extends Throwable> mono) {
441440
}
442441

443442
private <T extends Publisher<?>> T bodyToPublisher(ClientResponse response,
444-
BodyExtractor<T, ? super ClientHttpResponse> extractor,
445-
Function<Mono<? extends Throwable>, T> errorFunction) {
443+
T bodyPublisher, Function<Mono<? extends Throwable>, T> errorFunction) {
446444

447445
return this.statusHandlers.stream()
448446
.filter(statusHandler -> statusHandler.test(response.statusCode()))
449447
.findFirst()
450448
.map(statusHandler -> statusHandler.apply(response))
451449
.map(errorFunction::apply)
452-
.orElse(response.body(extractor));
450+
.orElse(bodyPublisher);
453451
}
454452

455453
private static Mono<WebClientResponseException> createResponseException(ClientResponse response) {

0 commit comments

Comments
 (0)