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
This commit is contained in:
Arjen Poutsma 2017-04-26 17:00:30 +02:00
parent 299b9d60fd
commit 0e7d6fc4d1
4 changed files with 15 additions and 16 deletions

View File

@ -359,7 +359,7 @@ class DefaultWebClient implements WebClient {
}
@Override
public <T> Mono<ResponseEntity<T>> bodyToEntity(Class<T> bodyType) {
public <T> Mono<ResponseEntity<T>> toEntity(Class<T> 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 <T> Mono<ResponseEntity<List<T>>> bodyToEntityList(Class<T> responseType) {
public <T> Mono<ResponseEntity<List<T>>> toEntityList(Class<T> responseType) {
return this.responseMono.flatMap(response ->
response.bodyToFlux(responseType).collectList().map(body -> {
HttpHeaders headers = response.headers().asHttpHeaders();

View File

@ -504,7 +504,7 @@ public interface WebClient {
* @param <T> response body type
* @return {@code Mono} with the result
*/
<T> Mono<ResponseEntity<T>> bodyToEntity(Class<T> bodyType);
<T> Mono<ResponseEntity<T>> toEntity(Class<T> bodyType);
/**
* A variant of {@link #bodyToFlux(Class)} collected via
@ -514,7 +514,7 @@ public interface WebClient {
* @param <T> the type of elements in the list
* @return {@code Mono} with the result
*/
<T> Mono<ResponseEntity<List<T>>> bodyToEntityList(Class<T> elementType);
<T> Mono<ResponseEntity<List<T>>> toEntityList(Class<T> elementType);
}

View File

@ -67,33 +67,33 @@ fun <T : Any> WebClient.ResponseSpec.bodyToFlux(type: KClass<T>): Flux<T> = body
inline fun <reified T : Any> WebClient.ResponseSpec.bodyToFlux(): Flux<T> = 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 <T : Any> WebClient.ResponseSpec.bodyToEntity(type: KClass<T>): Mono<ResponseEntity<T>> = bodyToEntity(type.java)
fun <T : Any> WebClient.ResponseSpec.toEntity(type: KClass<T>): Mono<ResponseEntity<T>> = toEntity(type.java)
/**
* Extension for [WebClient.ResponseSpec.bodyToEntity] providing a `bodyToEntity<Foo>()` variant.
* Extension for [WebClient.ResponseSpec.toEntity] providing a `bodyToEntity<Foo>()` variant.
*
* @author Sebastien Deleuze
* @since 5.0
*/
inline fun <reified T : Any> WebClient.ResponseSpec.bodyToEntity(): Mono<ResponseEntity<T>> = bodyToEntity(T::class.java)
inline fun <reified T : Any> WebClient.ResponseSpec.toEntity(): Mono<ResponseEntity<T>> = 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 <T : Any> WebClient.ResponseSpec.bodyToEntityList(type: KClass<T>): Mono<ResponseEntity<List<T>>> = bodyToEntityList(type.java)
fun <T : Any> WebClient.ResponseSpec.toEntityList(type: KClass<T>): Mono<ResponseEntity<List<T>>> = toEntityList(type.java)
/**
* Extension for [WebClient.ResponseSpec.bodyToEntityList] providing a `bodyToEntityList<Foo>()` variant.
* Extension for [WebClient.ResponseSpec.toEntityList] providing a `bodyToEntityList<Foo>()` variant.
*
* @author Sebastien Deleuze
* @since 5.0
*/
inline fun <reified T : Any> WebClient.ResponseSpec.bodyToEntityList(): Mono<ResponseEntity<List<T>>> = bodyToEntityList(T::class.java)
inline fun <reified T : Any> WebClient.ResponseSpec.toEntityList(): Mono<ResponseEntity<List<T>>> = toEntityList(T::class.java)

View File

@ -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 -> {