42
42
import org .springframework .http .HttpStatus ;
43
43
import org .springframework .http .MediaType ;
44
44
import org .springframework .http .client .reactive .ClientHttpRequest ;
45
- import org .springframework .http .client .reactive .ClientHttpResponse ;
46
45
import org .springframework .lang .Nullable ;
47
46
import org .springframework .util .Assert ;
48
47
import org .springframework .util .CollectionUtils ;
49
48
import org .springframework .util .LinkedMultiValueMap ;
50
49
import org .springframework .util .MimeType ;
51
50
import org .springframework .util .MultiValueMap ;
52
- import org .springframework .web .reactive .function .BodyExtractor ;
53
51
import org .springframework .web .reactive .function .BodyExtractors ;
54
52
import org .springframework .web .reactive .function .BodyInserter ;
55
53
import org .springframework .web .reactive .function .BodyInserters ;
@@ -405,16 +403,17 @@ public ResponseSpec onStatus(Predicate<HttpStatus> statusPredicate,
405
403
@ Override
406
404
@ SuppressWarnings ("unchecked" )
407
405
public <T > Mono <T > bodyToMono (Class <T > bodyType ) {
406
+ // Use bodyToMono (vs BodyExtractors) to ensure proper handling of Void.class...
408
407
return this .responseMono .flatMap (
409
- response -> bodyToPublisher (response , BodyExtractors . toMono (bodyType ),
408
+ response -> bodyToPublisher (response , response . bodyToMono (bodyType ),
410
409
this ::monoThrowableToMono ));
411
410
}
412
411
413
412
@ Override
414
413
@ SuppressWarnings ("unchecked" )
415
414
public <T > Mono <T > bodyToMono (ParameterizedTypeReference <T > typeReference ) {
416
415
return this .responseMono .flatMap (
417
- response -> bodyToPublisher (response , BodyExtractors . toMono (typeReference ),
416
+ response -> bodyToPublisher (response , response . bodyToMono (typeReference ),
418
417
this ::monoThrowableToMono ));
419
418
}
420
419
@@ -425,14 +424,14 @@ private <T> Mono<T> monoThrowableToMono(Mono<? extends Throwable> mono) {
425
424
@ Override
426
425
public <T > Flux <T > bodyToFlux (Class <T > elementType ) {
427
426
return this .responseMono .flatMapMany (
428
- response -> bodyToPublisher (response , BodyExtractors . toFlux (elementType ),
427
+ response -> bodyToPublisher (response , response . bodyToFlux (elementType ),
429
428
this ::monoThrowableToFlux ));
430
429
}
431
430
432
431
@ Override
433
432
public <T > Flux <T > bodyToFlux (ParameterizedTypeReference <T > typeReference ) {
434
433
return this .responseMono .flatMapMany (
435
- response -> bodyToPublisher (response , BodyExtractors . toFlux (typeReference ),
434
+ response -> bodyToPublisher (response , response . bodyToFlux (typeReference ),
436
435
this ::monoThrowableToFlux ));
437
436
}
438
437
@@ -441,15 +440,14 @@ private <T> Flux<T> monoThrowableToFlux(Mono<? extends Throwable> mono) {
441
440
}
442
441
443
442
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 ) {
446
444
447
445
return this .statusHandlers .stream ()
448
446
.filter (statusHandler -> statusHandler .test (response .statusCode ()))
449
447
.findFirst ()
450
448
.map (statusHandler -> statusHandler .apply (response ))
451
449
.map (errorFunction ::apply )
452
- .orElse (response . body ( extractor ) );
450
+ .orElse (bodyPublisher );
453
451
}
454
452
455
453
private static Mono <WebClientResponseException > createResponseException (ClientResponse response ) {
0 commit comments