diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java index 071df90393b..084d9fb059b 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClient.java @@ -359,7 +359,7 @@ class DefaultWebClient implements WebClient { } @Override - public Mono> bodyToEntity(Class bodyType) { + public Mono> toEntity(Class bodyType) { return this.responseMono.flatMap(response -> response.bodyToMono(bodyType).map(body -> { HttpHeaders headers = response.headers().asHttpHeaders(); @@ -369,7 +369,7 @@ class DefaultWebClient implements WebClient { } @Override - public Mono>> bodyToEntityList(Class responseType) { + public Mono>> toEntityList(Class responseType) { return this.responseMono.flatMap(response -> response.bodyToFlux(responseType).collectList().map(body -> { HttpHeaders headers = response.headers().asHttpHeaders(); 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 20d5af15be5..8e6d8d8d355 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 @@ -504,7 +504,7 @@ public interface WebClient { * @param response body type * @return {@code Mono} with the result */ - Mono> bodyToEntity(Class bodyType); + Mono> toEntity(Class bodyType); /** * A variant of {@link #bodyToFlux(Class)} collected via @@ -514,7 +514,7 @@ public interface WebClient { * @param the type of elements in the list * @return {@code Mono} with the result */ - Mono>> bodyToEntityList(Class elementType); + Mono>> toEntityList(Class elementType); } diff --git a/spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/client/WebClientExtensions.kt b/spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/client/WebClientExtensions.kt index 4f68d891847..5f8d2d59a3c 100644 --- a/spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/client/WebClientExtensions.kt +++ b/spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/client/WebClientExtensions.kt @@ -67,33 +67,33 @@ fun WebClient.ResponseSpec.bodyToFlux(type: KClass): Flux = body inline fun WebClient.ResponseSpec.bodyToFlux(): Flux = bodyToFlux(T::class.java) /** - * Extension for [WebClient.ResponseSpec.bodyToEntity] providing a [KClass] based variant. + * Extension for [WebClient.ResponseSpec.toEntity] providing a [KClass] based variant. * * @author Sebastien Deleuze * @since 5.0 */ -fun WebClient.ResponseSpec.bodyToEntity(type: KClass): Mono> = bodyToEntity(type.java) +fun WebClient.ResponseSpec.toEntity(type: KClass): Mono> = toEntity(type.java) /** - * Extension for [WebClient.ResponseSpec.bodyToEntity] providing a `bodyToEntity()` variant. + * Extension for [WebClient.ResponseSpec.toEntity] providing a `bodyToEntity()` variant. * * @author Sebastien Deleuze * @since 5.0 */ -inline fun WebClient.ResponseSpec.bodyToEntity(): Mono> = bodyToEntity(T::class.java) +inline fun WebClient.ResponseSpec.toEntity(): Mono> = toEntity(T::class.java) /** - * Extension for [WebClient.ResponseSpec.bodyToEntityList] providing a [KClass] based variant. + * Extension for [WebClient.ResponseSpec.toEntityList] providing a [KClass] based variant. * * @author Sebastien Deleuze * @since 5.0 */ -fun WebClient.ResponseSpec.bodyToEntityList(type: KClass): Mono>> = bodyToEntityList(type.java) +fun WebClient.ResponseSpec.toEntityList(type: KClass): Mono>> = toEntityList(type.java) /** - * Extension for [WebClient.ResponseSpec.bodyToEntityList] providing a `bodyToEntityList()` variant. + * Extension for [WebClient.ResponseSpec.toEntityList] providing a `bodyToEntityList()` variant. * * @author Sebastien Deleuze * @since 5.0 */ -inline fun WebClient.ResponseSpec.bodyToEntityList(): Mono>> = bodyToEntityList(T::class.java) +inline fun WebClient.ResponseSpec.toEntityList(): Mono>> = toEntityList(T::class.java) diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java index 6d6f2d8f169..63946eb45f4 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java @@ -38,8 +38,7 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.http.codec.Pojo; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.*; /** * Integration tests using a {@link ExchangeFunction} through {@link WebClient}. @@ -169,7 +168,7 @@ public class WebClientIntegrationTests { .uri("/json") .accept(MediaType.APPLICATION_JSON) .retrieve() - .bodyToEntity(String.class); + .toEntity(String.class); StepVerifier.create(result) .consumeNextWith(entity -> { @@ -196,7 +195,7 @@ public class WebClientIntegrationTests { .uri("/json") .accept(MediaType.APPLICATION_JSON) .retrieve() - .bodyToEntityList(Pojo.class); + .toEntityList(Pojo.class); StepVerifier.create(result) .consumeNextWith(entity -> {