Skip to content

Commit 0e7d6fc

Browse files
committed
Rename WebClient.ResponseSpec.bodyToEntity[List] to toEntity[List]
This commit renames `WebClient.ResponseSpec.bodyToEntity` to `toEntity` and similarly renames `WebClient.ResponseSpec.bodyToEntityList` to `toEntityList`. In both cases, the `body` prefix was dropped because the return value contains more than the body. Issue: SPR-15486
1 parent 299b9d6 commit 0e7d6fc

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ public <T> Flux<T> bodyToFlux(Class<T> elementType) {
359359
}
360360

361361
@Override
362-
public <T> Mono<ResponseEntity<T>> bodyToEntity(Class<T> bodyType) {
362+
public <T> Mono<ResponseEntity<T>> toEntity(Class<T> bodyType) {
363363
return this.responseMono.flatMap(response ->
364364
response.bodyToMono(bodyType).map(body -> {
365365
HttpHeaders headers = response.headers().asHttpHeaders();
@@ -369,7 +369,7 @@ public <T> Mono<ResponseEntity<T>> bodyToEntity(Class<T> bodyType) {
369369
}
370370

371371
@Override
372-
public <T> Mono<ResponseEntity<List<T>>> bodyToEntityList(Class<T> responseType) {
372+
public <T> Mono<ResponseEntity<List<T>>> toEntityList(Class<T> responseType) {
373373
return this.responseMono.flatMap(response ->
374374
response.bodyToFlux(responseType).collectList().map(body -> {
375375
HttpHeaders headers = response.headers().asHttpHeaders();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ interface ResponseSpec {
504504
* @param <T> response body type
505505
* @return {@code Mono} with the result
506506
*/
507-
<T> Mono<ResponseEntity<T>> bodyToEntity(Class<T> bodyType);
507+
<T> Mono<ResponseEntity<T>> toEntity(Class<T> bodyType);
508508

509509
/**
510510
* A variant of {@link #bodyToFlux(Class)} collected via
@@ -514,7 +514,7 @@ interface ResponseSpec {
514514
* @param <T> the type of elements in the list
515515
* @return {@code Mono} with the result
516516
*/
517-
<T> Mono<ResponseEntity<List<T>>> bodyToEntityList(Class<T> elementType);
517+
<T> Mono<ResponseEntity<List<T>>> toEntityList(Class<T> elementType);
518518

519519
}
520520

spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/client/WebClientExtensions.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,33 +67,33 @@ fun <T : Any> WebClient.ResponseSpec.bodyToFlux(type: KClass<T>): Flux<T> = body
6767
inline fun <reified T : Any> WebClient.ResponseSpec.bodyToFlux(): Flux<T> = bodyToFlux(T::class.java)
6868

6969
/**
70-
* Extension for [WebClient.ResponseSpec.bodyToEntity] providing a [KClass] based variant.
70+
* Extension for [WebClient.ResponseSpec.toEntity] providing a [KClass] based variant.
7171
*
7272
* @author Sebastien Deleuze
7373
* @since 5.0
7474
*/
75-
fun <T : Any> WebClient.ResponseSpec.bodyToEntity(type: KClass<T>): Mono<ResponseEntity<T>> = bodyToEntity(type.java)
75+
fun <T : Any> WebClient.ResponseSpec.toEntity(type: KClass<T>): Mono<ResponseEntity<T>> = toEntity(type.java)
7676

7777
/**
78-
* Extension for [WebClient.ResponseSpec.bodyToEntity] providing a `bodyToEntity<Foo>()` variant.
78+
* Extension for [WebClient.ResponseSpec.toEntity] providing a `bodyToEntity<Foo>()` variant.
7979
*
8080
* @author Sebastien Deleuze
8181
* @since 5.0
8282
*/
83-
inline fun <reified T : Any> WebClient.ResponseSpec.bodyToEntity(): Mono<ResponseEntity<T>> = bodyToEntity(T::class.java)
83+
inline fun <reified T : Any> WebClient.ResponseSpec.toEntity(): Mono<ResponseEntity<T>> = toEntity(T::class.java)
8484

8585
/**
86-
* Extension for [WebClient.ResponseSpec.bodyToEntityList] providing a [KClass] based variant.
86+
* Extension for [WebClient.ResponseSpec.toEntityList] providing a [KClass] based variant.
8787
*
8888
* @author Sebastien Deleuze
8989
* @since 5.0
9090
*/
91-
fun <T : Any> WebClient.ResponseSpec.bodyToEntityList(type: KClass<T>): Mono<ResponseEntity<List<T>>> = bodyToEntityList(type.java)
91+
fun <T : Any> WebClient.ResponseSpec.toEntityList(type: KClass<T>): Mono<ResponseEntity<List<T>>> = toEntityList(type.java)
9292

9393
/**
94-
* Extension for [WebClient.ResponseSpec.bodyToEntityList] providing a `bodyToEntityList<Foo>()` variant.
94+
* Extension for [WebClient.ResponseSpec.toEntityList] providing a `bodyToEntityList<Foo>()` variant.
9595
*
9696
* @author Sebastien Deleuze
9797
* @since 5.0
9898
*/
99-
inline fun <reified T : Any> WebClient.ResponseSpec.bodyToEntityList(): Mono<ResponseEntity<List<T>>> = bodyToEntityList(T::class.java)
99+
inline fun <reified T : Any> WebClient.ResponseSpec.toEntityList(): Mono<ResponseEntity<List<T>>> = toEntityList(T::class.java)

spring-webflux/src/test/java/org/springframework/web/reactive/function/client/WebClientIntegrationTests.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838
import org.springframework.http.ResponseEntity;
3939
import org.springframework.http.codec.Pojo;
4040

41-
import static org.junit.Assert.assertEquals;
42-
import static org.junit.Assert.assertThat;
41+
import static org.junit.Assert.*;
4342

4443
/**
4544
* Integration tests using a {@link ExchangeFunction} through {@link WebClient}.
@@ -169,7 +168,7 @@ public void jsonStringRetrieveEntity() throws Exception {
169168
.uri("/json")
170169
.accept(MediaType.APPLICATION_JSON)
171170
.retrieve()
172-
.bodyToEntity(String.class);
171+
.toEntity(String.class);
173172

174173
StepVerifier.create(result)
175174
.consumeNextWith(entity -> {
@@ -196,7 +195,7 @@ public void jsonStringRetrieveEntityList() throws Exception {
196195
.uri("/json")
197196
.accept(MediaType.APPLICATION_JSON)
198197
.retrieve()
199-
.bodyToEntityList(Pojo.class);
198+
.toEntityList(Pojo.class);
200199

201200
StepVerifier.create(result)
202201
.consumeNextWith(entity -> {

0 commit comments

Comments
 (0)