Use elementClass and elementTypeRef consistently
This commit is contained in:
parent
88d7fede36
commit
08a5196c3a
|
@ -157,24 +157,24 @@ final class DefaultRSocketRequester implements RSocketRequester {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ResponseSpec data(Object producer, Class<?> elementType) {
|
||||
public ResponseSpec data(Object producer, Class<?> elementClass) {
|
||||
Assert.notNull(producer, "'producer' must not be null");
|
||||
Assert.notNull(elementType, "'dataType' must not be null");
|
||||
Assert.notNull(elementClass, "'elementClass' must not be null");
|
||||
ReactiveAdapter adapter = strategies.reactiveAdapterRegistry().getAdapter(producer.getClass());
|
||||
Assert.notNull(adapter, "'producer' type is unknown to ReactiveAdapterRegistry");
|
||||
return toResponseSpec(adapter.toPublisher(producer), ResolvableType.forClass(elementType));
|
||||
return toResponseSpec(adapter.toPublisher(producer), ResolvableType.forClass(elementClass));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseSpec data(Object producer, ParameterizedTypeReference<?> dataTypeRef) {
|
||||
public ResponseSpec data(Object producer, ParameterizedTypeReference<?> elementTypeRef) {
|
||||
Assert.notNull(producer, "'producer' must not be null");
|
||||
Assert.notNull(dataTypeRef, "'dataTypeRef' must not be null");
|
||||
Assert.notNull(elementTypeRef, "'elementTypeRef' must not be null");
|
||||
ReactiveAdapter adapter = strategies.reactiveAdapterRegistry().getAdapter(producer.getClass());
|
||||
Assert.notNull(adapter, "'producer' type is unknown to ReactiveAdapterRegistry");
|
||||
return toResponseSpec(adapter.toPublisher(producer), ResolvableType.forType(dataTypeRef));
|
||||
return toResponseSpec(adapter.toPublisher(producer), ResolvableType.forType(elementTypeRef));
|
||||
}
|
||||
|
||||
private ResponseSpec toResponseSpec(Object input, ResolvableType dataType) {
|
||||
private ResponseSpec toResponseSpec(Object input, ResolvableType elementType) {
|
||||
ReactiveAdapter adapter = strategies.reactiveAdapterRegistry().getAdapter(input.getClass());
|
||||
Publisher<?> publisher;
|
||||
if (input instanceof Publisher) {
|
||||
|
@ -192,24 +192,24 @@ final class DefaultRSocketRequester implements RSocketRequester {
|
|||
return new DefaultResponseSpec(payloadMono);
|
||||
}
|
||||
|
||||
if (isVoid(dataType) || (adapter != null && adapter.isNoValue())) {
|
||||
if (isVoid(elementType) || (adapter != null && adapter.isNoValue())) {
|
||||
Mono<Payload> payloadMono = Mono.when(publisher).then(emptyPayload());
|
||||
return new DefaultResponseSpec(payloadMono);
|
||||
}
|
||||
|
||||
Encoder<?> encoder = dataType != ResolvableType.NONE && !Object.class.equals(dataType.resolve()) ?
|
||||
strategies.encoder(dataType, dataMimeType) : null;
|
||||
Encoder<?> encoder = elementType != ResolvableType.NONE && !Object.class.equals(elementType.resolve()) ?
|
||||
strategies.encoder(elementType, dataMimeType) : null;
|
||||
|
||||
if (adapter != null && !adapter.isMultiValue()) {
|
||||
Mono<Payload> payloadMono = Mono.from(publisher)
|
||||
.map(value -> encodeData(value, dataType, encoder))
|
||||
.map(value -> encodeData(value, elementType, encoder))
|
||||
.map(this::firstPayload)
|
||||
.switchIfEmpty(emptyPayload());
|
||||
return new DefaultResponseSpec(payloadMono);
|
||||
}
|
||||
|
||||
Flux<Payload> payloadFlux = Flux.from(publisher)
|
||||
.map(value -> encodeData(value, dataType, encoder))
|
||||
.map(value -> encodeData(value, elementType, encoder))
|
||||
.switchOnFirst((signal, inner) -> {
|
||||
DataBuffer data = signal.get();
|
||||
if (data != null) {
|
||||
|
@ -226,16 +226,16 @@ final class DefaultRSocketRequester implements RSocketRequester {
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> DataBuffer encodeData(T value, ResolvableType valueType, @Nullable Encoder<?> encoder) {
|
||||
private <T> DataBuffer encodeData(T value, ResolvableType elementType, @Nullable Encoder<?> encoder) {
|
||||
if (value instanceof DataBuffer) {
|
||||
return (DataBuffer) value;
|
||||
}
|
||||
if (encoder == null) {
|
||||
valueType = ResolvableType.forInstance(value);
|
||||
encoder = strategies.encoder(valueType, dataMimeType);
|
||||
elementType = ResolvableType.forInstance(value);
|
||||
encoder = strategies.encoder(elementType, dataMimeType);
|
||||
}
|
||||
return ((Encoder<T>) encoder).encodeValue(
|
||||
value, bufferFactory(), valueType, dataMimeType, EMPTY_HINTS);
|
||||
value, bufferFactory(), elementType, dataMimeType, EMPTY_HINTS);
|
||||
}
|
||||
|
||||
private Payload firstPayload(DataBuffer data) {
|
||||
|
|
|
@ -243,10 +243,10 @@ public interface RSocketRequester {
|
|||
* @param producer the source of payload data value(s). This must be a
|
||||
* {@link Publisher} or another producer adaptable to a
|
||||
* {@code Publisher} via {@link ReactiveAdapterRegistry}
|
||||
* @param elementType the type of values to be produced
|
||||
* @param elementClass the type of values to be produced
|
||||
* @return spec for declaring the expected response
|
||||
*/
|
||||
ResponseSpec data(Object producer, Class<?> elementType);
|
||||
ResponseSpec data(Object producer, Class<?> elementClass);
|
||||
|
||||
/**
|
||||
* Alternative of {@link #data(Object, Class)} but with a
|
||||
|
|
|
@ -273,8 +273,8 @@ class DefaultWebTestClient implements WebTestClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public RequestHeadersSpec<?> body(Object producer, ParameterizedTypeReference<?> elementType) {
|
||||
this.bodySpec.body(producer, elementType);
|
||||
public RequestHeadersSpec<?> body(Object producer, ParameterizedTypeReference<?> elementTypeRef) {
|
||||
this.bodySpec.body(producer, elementTypeRef);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -285,8 +285,8 @@ class DefaultWebTestClient implements WebTestClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public <T, S extends Publisher<T>> RequestHeadersSpec<?> body(S publisher, ParameterizedTypeReference<T> elementType) {
|
||||
this.bodySpec.body(publisher, elementType);
|
||||
public <T, S extends Publisher<T>> RequestHeadersSpec<?> body(S publisher, ParameterizedTypeReference<T> elementTypeRef) {
|
||||
this.bodySpec.body(publisher, elementTypeRef);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -379,14 +379,14 @@ class DefaultWebTestClient implements WebTestClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public <T> FluxExchangeResult<T> returnResult(Class<T> elementType) {
|
||||
Flux<T> body = this.response.bodyToFlux(elementType);
|
||||
public <T> FluxExchangeResult<T> returnResult(Class<T> elementClass) {
|
||||
Flux<T> body = this.response.bodyToFlux(elementClass);
|
||||
return new FluxExchangeResult<>(this.exchangeResult, body);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> FluxExchangeResult<T> returnResult(ParameterizedTypeReference<T> elementType) {
|
||||
Flux<T> body = this.response.bodyToFlux(elementType);
|
||||
public <T> FluxExchangeResult<T> returnResult(ParameterizedTypeReference<T> elementTypeRef) {
|
||||
Flux<T> body = this.response.bodyToFlux(elementTypeRef);
|
||||
return new FluxExchangeResult<>(this.exchangeResult, body);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -660,11 +660,11 @@ public interface WebTestClient {
|
|||
* @param producer the producer to write to the request. This must be a
|
||||
* {@link Publisher} or another producer adaptable to a
|
||||
* {@code Publisher} via {@link ReactiveAdapterRegistry}
|
||||
* @param elementType the type reference of elements contained in the producer
|
||||
* @param elementTypeRef the type reference of elements contained in the producer
|
||||
* @return spec for decoding the response
|
||||
* @since 5.2
|
||||
*/
|
||||
RequestHeadersSpec<?> body(Object producer, ParameterizedTypeReference<?> elementType);
|
||||
RequestHeadersSpec<?> body(Object producer, ParameterizedTypeReference<?> elementTypeRef);
|
||||
|
||||
/**
|
||||
* Set the body of the request to the given asynchronous {@code Publisher}.
|
||||
|
@ -679,13 +679,13 @@ public interface WebTestClient {
|
|||
/**
|
||||
* Set the body of the request to the given asynchronous {@code Publisher}.
|
||||
* @param publisher the request body data
|
||||
* @param elementType the type reference of elements contained in the publisher
|
||||
* @param elementTypeRef the type reference of elements contained in the publisher
|
||||
* @param <T> the type of the elements contained in the publisher
|
||||
* @param <S> the type of the {@code Publisher}
|
||||
* @return spec for decoding the response
|
||||
* @since 5.2
|
||||
*/
|
||||
<T, S extends Publisher<T>> RequestHeadersSpec<?> body(S publisher, ParameterizedTypeReference<T> elementType);
|
||||
<T, S extends Publisher<T>> RequestHeadersSpec<?> body(S publisher, ParameterizedTypeReference<T> elementTypeRef);
|
||||
|
||||
/**
|
||||
* Set the body of the request to the given {@code BodyInserter}.
|
||||
|
@ -796,13 +796,13 @@ public interface WebTestClient {
|
|||
* {@code expectBody(Void.class)} which ensures that resources are
|
||||
* released regardless of whether the response has content or not.
|
||||
*/
|
||||
<T> FluxExchangeResult<T> returnResult(Class<T> elementType);
|
||||
<T> FluxExchangeResult<T> returnResult(Class<T> elementClass);
|
||||
|
||||
/**
|
||||
* Alternative to {@link #returnResult(Class)} that accepts information
|
||||
* about a target type with generics.
|
||||
*/
|
||||
<T> FluxExchangeResult<T> returnResult(ParameterizedTypeReference<T> elementType);
|
||||
<T> FluxExchangeResult<T> returnResult(ParameterizedTypeReference<T> elementTypeRef);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -72,12 +72,12 @@ public abstract class BodyExtractors {
|
|||
|
||||
/**
|
||||
* Variant of {@link #toMono(Class)} for type information with generics.
|
||||
* @param typeRef the type reference for the type to decode to
|
||||
* @param elementTypeRef the type reference for the type to decode to
|
||||
* @param <T> the element type to decode to
|
||||
* @return {@code BodyExtractor} for {@code Mono<T>}
|
||||
*/
|
||||
public static <T> BodyExtractor<Mono<T>, ReactiveHttpInputMessage> toMono(ParameterizedTypeReference<T> typeRef) {
|
||||
return toMono(ResolvableType.forType(typeRef.getType()));
|
||||
public static <T> BodyExtractor<Mono<T>, ReactiveHttpInputMessage> toMono(ParameterizedTypeReference<T> elementTypeRef) {
|
||||
return toMono(ResolvableType.forType(elementTypeRef.getType()));
|
||||
}
|
||||
|
||||
private static <T> BodyExtractor<Mono<T>, ReactiveHttpInputMessage> toMono(ResolvableType elementType) {
|
||||
|
|
|
@ -92,7 +92,7 @@ public abstract class BodyInserters {
|
|||
* @see #fromProducer(Object, Class)
|
||||
*/
|
||||
public static <T> BodyInserter<T, ReactiveHttpOutputMessage> fromObject(T body) {
|
||||
Assert.notNull(body, "Body must not be null");
|
||||
Assert.notNull(body, "'body' must not be null");
|
||||
Assert.isNull(registry.getAdapter(body.getClass()), "'body' should be an object, for reactive types use a variant specifying a publisher/producer and its related element type");
|
||||
return (message, context) ->
|
||||
writeWithMessageWriters(message, context, Mono.just(body), ResolvableType.forInstance(body), null);
|
||||
|
@ -107,7 +107,7 @@ public abstract class BodyInserters {
|
|||
* {@link org.springframework.web.reactive.function.server.ServerResponse ServerResponse}.
|
||||
* @param <T> the type of the body
|
||||
* @param producer the source of body value(s).
|
||||
* @param elementClass the type of values to be produced
|
||||
* @param elementClass the class of values to be produced
|
||||
* @return the inserter to write a producer
|
||||
* @since 5.2
|
||||
*/
|
||||
|
@ -129,17 +129,18 @@ public abstract class BodyInserters {
|
|||
* {@link org.springframework.web.reactive.function.server.ServerResponse ServerResponse}.
|
||||
* @param <T> the type of the body
|
||||
* @param producer the source of body value(s).
|
||||
* @param elementType the type of values to be produced
|
||||
* @param elementTypeRef the type of values to be produced
|
||||
* @return the inserter to write a producer
|
||||
* @since 5.2
|
||||
*/
|
||||
public static <T> BodyInserter<T, ReactiveHttpOutputMessage> fromProducer(T producer, ParameterizedTypeReference<?> elementType) {
|
||||
public static <T> BodyInserter<T, ReactiveHttpOutputMessage> fromProducer(T producer,
|
||||
ParameterizedTypeReference<?> elementTypeRef) {
|
||||
Assert.notNull(producer, "'producer' must not be null");
|
||||
Assert.notNull(elementType, "'elementType' must not be null");
|
||||
Assert.notNull(elementTypeRef, "'elementTypeRef' must not be null");
|
||||
ReactiveAdapter adapter = ReactiveAdapterRegistry.getSharedInstance().getAdapter(producer.getClass());
|
||||
Assert.notNull(adapter, "'producer' type is unknown to ReactiveAdapterRegistry");
|
||||
return (message, context) ->
|
||||
writeWithMessageWriters(message, context, producer, ResolvableType.forType(elementType), adapter);
|
||||
writeWithMessageWriters(message, context, producer, ResolvableType.forType(elementTypeRef), adapter);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -148,7 +149,7 @@ public abstract class BodyInserters {
|
|||
* {@link org.springframework.web.reactive.function.client.WebClient WebClient} and
|
||||
* {@link org.springframework.web.reactive.function.server.ServerResponse ServerResponse}.
|
||||
* @param publisher the publisher to write with
|
||||
* @param elementClass the type of elements in the publisher
|
||||
* @param elementClass the class of elements in the publisher
|
||||
* @param <T> the type of the elements contained in the publisher
|
||||
* @param <P> the {@code Publisher} type
|
||||
* @return the inserter to write a {@code Publisher}
|
||||
|
@ -156,8 +157,8 @@ public abstract class BodyInserters {
|
|||
public static <T, P extends Publisher<T>> BodyInserter<P, ReactiveHttpOutputMessage> fromPublisher(
|
||||
P publisher, Class<T> elementClass) {
|
||||
|
||||
Assert.notNull(publisher, "Publisher must not be null");
|
||||
Assert.notNull(elementClass, "Element Class must not be null");
|
||||
Assert.notNull(publisher, "'publisher' must not be null");
|
||||
Assert.notNull(elementClass, "'elementClass' must not be null");
|
||||
return (message, context) ->
|
||||
writeWithMessageWriters(message, context, publisher, ResolvableType.forClass(elementClass), null);
|
||||
}
|
||||
|
@ -168,18 +169,18 @@ public abstract class BodyInserters {
|
|||
* {@link org.springframework.web.reactive.function.client.WebClient WebClient} and
|
||||
* {@link org.springframework.web.reactive.function.server.ServerResponse ServerResponse}.
|
||||
* @param publisher the publisher to write with
|
||||
* @param typeReference the type of elements contained in the publisher
|
||||
* @param elementTypeRef the type of elements contained in the publisher
|
||||
* @param <T> the type of the elements contained in the publisher
|
||||
* @param <P> the {@code Publisher} type
|
||||
* @return the inserter to write a {@code Publisher}
|
||||
*/
|
||||
public static <T, P extends Publisher<T>> BodyInserter<P, ReactiveHttpOutputMessage> fromPublisher(
|
||||
P publisher, ParameterizedTypeReference<T> typeReference) {
|
||||
P publisher, ParameterizedTypeReference<T> elementTypeRef) {
|
||||
|
||||
Assert.notNull(publisher, "Publisher must not be null");
|
||||
Assert.notNull(typeReference, "ParameterizedTypeReference must not be null");
|
||||
Assert.notNull(publisher, "'publisher' must not be null");
|
||||
Assert.notNull(elementTypeRef, "'elementTypeRef' must not be null");
|
||||
return (message, context) ->
|
||||
writeWithMessageWriters(message, context, publisher, ResolvableType.forType(typeReference.getType()), null);
|
||||
writeWithMessageWriters(message, context, publisher, ResolvableType.forType(elementTypeRef.getType()), null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -191,7 +192,7 @@ public abstract class BodyInserters {
|
|||
* @return the inserter to write a {@code Publisher}
|
||||
*/
|
||||
public static <T extends Resource> BodyInserter<T, ReactiveHttpOutputMessage> fromResource(T resource) {
|
||||
Assert.notNull(resource, "Resource must not be null");
|
||||
Assert.notNull(resource, "'resource' must not be null");
|
||||
return (outputMessage, context) -> {
|
||||
ResolvableType elementType = RESOURCE_TYPE;
|
||||
HttpMessageWriter<Resource> writer = findWriter(context, elementType, null);
|
||||
|
@ -213,7 +214,7 @@ public abstract class BodyInserters {
|
|||
public static <T, S extends Publisher<ServerSentEvent<T>>> BodyInserter<S, ServerHttpResponse> fromServerSentEvents(
|
||||
S eventsPublisher) {
|
||||
|
||||
Assert.notNull(eventsPublisher, "Publisher must not be null");
|
||||
Assert.notNull(eventsPublisher, "'eventsPublisher' must not be null");
|
||||
return (serverResponse, context) -> {
|
||||
ResolvableType elementType = SSE_TYPE;
|
||||
MediaType mediaType = MediaType.TEXT_EVENT_STREAM;
|
||||
|
@ -330,7 +331,7 @@ public abstract class BodyInserters {
|
|||
public static <T extends Publisher<DataBuffer>> BodyInserter<T, ReactiveHttpOutputMessage> fromDataBuffers(
|
||||
T publisher) {
|
||||
|
||||
Assert.notNull(publisher, "Publisher must not be null");
|
||||
Assert.notNull(publisher, "'publisher' must not be null");
|
||||
return (outputMessage, context) -> outputMessage.writeWith(publisher);
|
||||
}
|
||||
|
||||
|
|
|
@ -108,15 +108,15 @@ public interface ClientResponse {
|
|||
|
||||
/**
|
||||
* Extract the body to a {@code Mono}.
|
||||
* @param typeReference a type reference describing the expected response body type
|
||||
* @param elementTypeRef the type reference of element in the {@code Mono}
|
||||
* @param <T> the element type
|
||||
* @return a mono containing the body of the given type {@code T}
|
||||
*/
|
||||
<T> Mono<T> bodyToMono(ParameterizedTypeReference<T> typeReference);
|
||||
<T> Mono<T> bodyToMono(ParameterizedTypeReference<T> elementTypeRef);
|
||||
|
||||
/**
|
||||
* Extract the body to a {@code Flux}.
|
||||
* @param elementClass the class of element in the {@code Flux}
|
||||
* @param elementClass the class of elements in the {@code Flux}
|
||||
* @param <T> the element type
|
||||
* @return a flux containing the body of the given type {@code T}
|
||||
*/
|
||||
|
@ -124,43 +124,43 @@ public interface ClientResponse {
|
|||
|
||||
/**
|
||||
* Extract the body to a {@code Flux}.
|
||||
* @param typeReference a type reference describing the expected response body type
|
||||
* @param elementTypeRef the type reference of elements in the {@code Flux}
|
||||
* @param <T> the element type
|
||||
* @return a flux containing the body of the given type {@code T}
|
||||
*/
|
||||
<T> Flux<T> bodyToFlux(ParameterizedTypeReference<T> typeReference);
|
||||
<T> Flux<T> bodyToFlux(ParameterizedTypeReference<T> elementTypeRef);
|
||||
|
||||
/**
|
||||
* Return this response as a delayed {@code ResponseEntity}.
|
||||
* @param bodyType the expected response body type
|
||||
* @param bodyClass the expected response body type
|
||||
* @param <T> response body type
|
||||
* @return {@code Mono} with the {@code ResponseEntity}
|
||||
*/
|
||||
<T> Mono<ResponseEntity<T>> toEntity(Class<T> bodyType);
|
||||
<T> Mono<ResponseEntity<T>> toEntity(Class<T> bodyClass);
|
||||
|
||||
/**
|
||||
* Return this response as a delayed {@code ResponseEntity}.
|
||||
* @param typeReference a type reference describing the expected response body type
|
||||
* @param bodyTypeReference a type reference describing the expected response body type
|
||||
* @param <T> response body type
|
||||
* @return {@code Mono} with the {@code ResponseEntity}
|
||||
*/
|
||||
<T> Mono<ResponseEntity<T>> toEntity(ParameterizedTypeReference<T> typeReference);
|
||||
<T> Mono<ResponseEntity<T>> toEntity(ParameterizedTypeReference<T> bodyTypeReference);
|
||||
|
||||
/**
|
||||
* Return this response as a delayed list of {@code ResponseEntity}s.
|
||||
* @param elementType the expected response body list element type
|
||||
* @param elementClass the expected response body list element class
|
||||
* @param <T> the type of elements in the list
|
||||
* @return {@code Mono} with the list of {@code ResponseEntity}s
|
||||
*/
|
||||
<T> Mono<ResponseEntity<List<T>>> toEntityList(Class<T> elementType);
|
||||
<T> Mono<ResponseEntity<List<T>>> toEntityList(Class<T> elementClass);
|
||||
|
||||
/**
|
||||
* Return this response as a delayed list of {@code ResponseEntity}s.
|
||||
* @param typeReference a type reference describing the expected response body type
|
||||
* @param elementTypeRef the expected response body list element reference type
|
||||
* @param <T> the type of elements in the list
|
||||
* @return {@code Mono} with the list of {@code ResponseEntity}s
|
||||
*/
|
||||
<T> Mono<ResponseEntity<List<T>>> toEntityList(ParameterizedTypeReference<T> typeReference);
|
||||
<T> Mono<ResponseEntity<List<T>>> toEntityList(ParameterizedTypeReference<T> elementTypeRef);
|
||||
|
||||
|
||||
// Static builder methods
|
||||
|
|
|
@ -132,8 +132,8 @@ class DefaultClientResponse implements ClientResponse {
|
|||
}
|
||||
|
||||
@Override
|
||||
public <T> Mono<T> bodyToMono(ParameterizedTypeReference<T> typeReference) {
|
||||
return body(BodyExtractors.toMono(typeReference));
|
||||
public <T> Mono<T> bodyToMono(ParameterizedTypeReference<T> elementTypeRef) {
|
||||
return body(BodyExtractors.toMono(elementTypeRef));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -142,8 +142,8 @@ class DefaultClientResponse implements ClientResponse {
|
|||
}
|
||||
|
||||
@Override
|
||||
public <T> Flux<T> bodyToFlux(ParameterizedTypeReference<T> typeReference) {
|
||||
return body(BodyExtractors.toFlux(typeReference));
|
||||
public <T> Flux<T> bodyToFlux(ParameterizedTypeReference<T> elementTypeRef) {
|
||||
return body(BodyExtractors.toFlux(elementTypeRef));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -152,8 +152,8 @@ class DefaultClientResponse implements ClientResponse {
|
|||
}
|
||||
|
||||
@Override
|
||||
public <T> Mono<ResponseEntity<T>> toEntity(ParameterizedTypeReference<T> typeReference) {
|
||||
return toEntityInternal(bodyToMono(typeReference));
|
||||
public <T> Mono<ResponseEntity<T>> toEntity(ParameterizedTypeReference<T> bodyTypeReference) {
|
||||
return toEntityInternal(bodyToMono(bodyTypeReference));
|
||||
}
|
||||
|
||||
private <T> Mono<ResponseEntity<T>> toEntityInternal(Mono<T> bodyMono) {
|
||||
|
@ -166,13 +166,13 @@ class DefaultClientResponse implements ClientResponse {
|
|||
}
|
||||
|
||||
@Override
|
||||
public <T> Mono<ResponseEntity<List<T>>> toEntityList(Class<T> responseType) {
|
||||
return toEntityListInternal(bodyToFlux(responseType));
|
||||
public <T> Mono<ResponseEntity<List<T>>> toEntityList(Class<T> elementClass) {
|
||||
return toEntityListInternal(bodyToFlux(elementClass));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Mono<ResponseEntity<List<T>>> toEntityList(ParameterizedTypeReference<T> typeReference) {
|
||||
return toEntityListInternal(bodyToFlux(typeReference));
|
||||
public <T> Mono<ResponseEntity<List<T>>> toEntityList(ParameterizedTypeReference<T> elementTypeRef) {
|
||||
return toEntityListInternal(bodyToFlux(elementTypeRef));
|
||||
}
|
||||
|
||||
private <T> Mono<ResponseEntity<List<T>>> toEntityListInternal(Flux<T> bodyFlux) {
|
||||
|
|
|
@ -303,15 +303,15 @@ class DefaultWebClient implements WebClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public RequestHeadersSpec<?> body(Object producer, ParameterizedTypeReference<?> elementType) {
|
||||
this.inserter = BodyInserters.fromProducer(producer, elementType);
|
||||
public RequestHeadersSpec<?> body(Object producer, ParameterizedTypeReference<?> elementTypeRef) {
|
||||
this.inserter = BodyInserters.fromProducer(producer, elementTypeRef);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, P extends Publisher<T>> RequestHeadersSpec<?> body(
|
||||
P publisher, ParameterizedTypeReference<T> elementType) {
|
||||
this.inserter = BodyInserters.fromPublisher(publisher, elementType);
|
||||
P publisher, ParameterizedTypeReference<T> elementTypeRef) {
|
||||
this.inserter = BodyInserters.fromPublisher(publisher, elementTypeRef);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -449,27 +449,27 @@ class DefaultWebClient implements WebClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public <T> Mono<T> bodyToMono(Class<T> bodyType) {
|
||||
public <T> Mono<T> bodyToMono(Class<T> elementClass) {
|
||||
return this.responseMono.flatMap(response -> handleBody(response,
|
||||
response.bodyToMono(bodyType), mono -> mono.flatMap(Mono::error)));
|
||||
response.bodyToMono(elementClass), mono -> mono.flatMap(Mono::error)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Mono<T> bodyToMono(ParameterizedTypeReference<T> bodyType) {
|
||||
public <T> Mono<T> bodyToMono(ParameterizedTypeReference<T> elementTypeRef) {
|
||||
return this.responseMono.flatMap(response ->
|
||||
handleBody(response, response.bodyToMono(bodyType), mono -> mono.flatMap(Mono::error)));
|
||||
handleBody(response, response.bodyToMono(elementTypeRef), mono -> mono.flatMap(Mono::error)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Flux<T> bodyToFlux(Class<T> elementType) {
|
||||
public <T> Flux<T> bodyToFlux(Class<T> elementClass) {
|
||||
return this.responseMono.flatMapMany(response ->
|
||||
handleBody(response, response.bodyToFlux(elementType), mono -> mono.handle((t, sink) -> sink.error(t))));
|
||||
handleBody(response, response.bodyToFlux(elementClass), mono -> mono.handle((t, sink) -> sink.error(t))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Flux<T> bodyToFlux(ParameterizedTypeReference<T> elementType) {
|
||||
public <T> Flux<T> bodyToFlux(ParameterizedTypeReference<T> elementTypeRef) {
|
||||
return this.responseMono.flatMapMany(response ->
|
||||
handleBody(response, response.bodyToFlux(elementType), mono -> mono.handle((t, sink) -> sink.error(t))));
|
||||
handleBody(response, response.bodyToFlux(elementTypeRef), mono -> mono.handle((t, sink) -> sink.error(t))));
|
||||
}
|
||||
|
||||
private <T extends Publisher<?>> T handleBody(ClientResponse response,
|
||||
|
|
|
@ -580,11 +580,11 @@ public interface WebClient {
|
|||
* @param producer the producer to write to the request. This must be a
|
||||
* {@link Publisher} or another producer adaptable to a
|
||||
* {@code Publisher} via {@link ReactiveAdapterRegistry}
|
||||
* @param elementType the type reference of elements contained in the producer
|
||||
* @param elementTypeRef the type reference of elements contained in the producer
|
||||
* @return this builder
|
||||
* @since 5.2
|
||||
*/
|
||||
RequestHeadersSpec<?> body(Object producer, ParameterizedTypeReference<?> elementType);
|
||||
RequestHeadersSpec<?> body(Object producer, ParameterizedTypeReference<?> elementTypeRef);
|
||||
|
||||
/**
|
||||
* A shortcut for {@link #body(BodyInserter)} with a
|
||||
|
@ -613,13 +613,13 @@ public interface WebClient {
|
|||
* element type information that includes generics via a
|
||||
* {@link ParameterizedTypeReference}.
|
||||
* @param publisher the {@code Publisher} to write to the request
|
||||
* @param elementType the type reference of elements contained in the publisher
|
||||
* @param elementTypeRef the type reference of elements contained in the publisher
|
||||
* @param <T> the type of the elements contained in the publisher
|
||||
* @param <P> the type of the {@code Publisher}
|
||||
* @return this builder
|
||||
*/
|
||||
<T, P extends Publisher<T>> RequestHeadersSpec<?> body(P publisher,
|
||||
ParameterizedTypeReference<T> elementType);
|
||||
ParameterizedTypeReference<T> elementTypeRef);
|
||||
|
||||
/**
|
||||
* Set the body of the request using the given body inserter.
|
||||
|
@ -690,45 +690,45 @@ public interface WebClient {
|
|||
* Extract the body to a {@code Mono}. By default, if the response has status code 4xx or
|
||||
* 5xx, the {@code Mono} will contain a {@link WebClientException}. This can be overridden
|
||||
* with {@link #onStatus(Predicate, Function)}.
|
||||
* @param bodyType the expected response body type
|
||||
* @param elementClass the expected response body element class
|
||||
* @param <T> response body type
|
||||
* @return a mono containing the body, or a {@link WebClientResponseException} if the
|
||||
* status code is 4xx or 5xx
|
||||
*/
|
||||
<T> Mono<T> bodyToMono(Class<T> bodyType);
|
||||
<T> Mono<T> bodyToMono(Class<T> elementClass);
|
||||
|
||||
/**
|
||||
* Extract the body to a {@code Mono}. By default, if the response has status code 4xx or
|
||||
* 5xx, the {@code Mono} will contain a {@link WebClientException}. This can be overridden
|
||||
* with {@link #onStatus(Predicate, Function)}.
|
||||
* @param typeReference a type reference describing the expected response body type
|
||||
* @param elementTypeRef a type reference describing the expected response body element type
|
||||
* @param <T> response body type
|
||||
* @return a mono containing the body, or a {@link WebClientResponseException} if the
|
||||
* status code is 4xx or 5xx
|
||||
*/
|
||||
<T> Mono<T> bodyToMono(ParameterizedTypeReference<T> typeReference);
|
||||
<T> Mono<T> bodyToMono(ParameterizedTypeReference<T> elementTypeRef);
|
||||
|
||||
/**
|
||||
* Extract the body to a {@code Flux}. By default, if the response has status code 4xx or
|
||||
* 5xx, the {@code Flux} will contain a {@link WebClientException}. This can be overridden
|
||||
* with {@link #onStatus(Predicate, Function)}.
|
||||
* @param elementType the type of element in the response
|
||||
* @param elementClass the class of elements in the response
|
||||
* @param <T> the type of elements in the response
|
||||
* @return a flux containing the body, or a {@link WebClientResponseException} if the
|
||||
* status code is 4xx or 5xx
|
||||
*/
|
||||
<T> Flux<T> bodyToFlux(Class<T> elementType);
|
||||
<T> Flux<T> bodyToFlux(Class<T> elementClass);
|
||||
|
||||
/**
|
||||
* Extract the body to a {@code Flux}. By default, if the response has status code 4xx or
|
||||
* 5xx, the {@code Flux} will contain a {@link WebClientException}. This can be overridden
|
||||
* with {@link #onStatus(Predicate, Function)}.
|
||||
* @param typeReference a type reference describing the expected response body type
|
||||
* @param elementTypeRef a type reference describing the expected response body element type
|
||||
* @param <T> the type of elements in the response
|
||||
* @return a flux containing the body, or a {@link WebClientResponseException} if the
|
||||
* status code is 4xx or 5xx
|
||||
*/
|
||||
<T> Flux<T> bodyToFlux(ParameterizedTypeReference<T> typeReference);
|
||||
<T> Flux<T> bodyToFlux(ParameterizedTypeReference<T> elementTypeRef);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -103,8 +103,8 @@ public class ClientResponseWrapper implements ClientResponse {
|
|||
}
|
||||
|
||||
@Override
|
||||
public <T> Mono<T> bodyToMono(ParameterizedTypeReference<T> typeReference) {
|
||||
return this.delegate.bodyToMono(typeReference);
|
||||
public <T> Mono<T> bodyToMono(ParameterizedTypeReference<T> elementTypeRef) {
|
||||
return this.delegate.bodyToMono(elementTypeRef);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -113,8 +113,8 @@ public class ClientResponseWrapper implements ClientResponse {
|
|||
}
|
||||
|
||||
@Override
|
||||
public <T> Flux<T> bodyToFlux(ParameterizedTypeReference<T> typeReference) {
|
||||
return this.delegate.bodyToFlux(typeReference);
|
||||
public <T> Flux<T> bodyToFlux(ParameterizedTypeReference<T> elementTypeRef) {
|
||||
return this.delegate.bodyToFlux(elementTypeRef);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -123,18 +123,18 @@ public class ClientResponseWrapper implements ClientResponse {
|
|||
}
|
||||
|
||||
@Override
|
||||
public <T> Mono<ResponseEntity<T>> toEntity(ParameterizedTypeReference<T> typeReference) {
|
||||
return this.delegate.toEntity(typeReference);
|
||||
public <T> Mono<ResponseEntity<T>> toEntity(ParameterizedTypeReference<T> bodyTypeReference) {
|
||||
return this.delegate.toEntity(bodyTypeReference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Mono<ResponseEntity<List<T>>> toEntityList(Class<T> elementType) {
|
||||
return this.delegate.toEntityList(elementType);
|
||||
public <T> Mono<ResponseEntity<List<T>>> toEntityList(Class<T> elementClass) {
|
||||
return this.delegate.toEntityList(elementClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Mono<ResponseEntity<List<T>>> toEntityList(ParameterizedTypeReference<T> typeReference) {
|
||||
return this.delegate.toEntityList(typeReference);
|
||||
public <T> Mono<ResponseEntity<List<T>>> toEntityList(ParameterizedTypeReference<T> elementTypeRef) {
|
||||
return this.delegate.toEntityList(elementTypeRef);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -247,9 +247,9 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Mono<ServerResponse> body(Object producer, ParameterizedTypeReference<?> elementType) {
|
||||
public Mono<ServerResponse> body(Object producer, ParameterizedTypeReference<?> elementTypeRef) {
|
||||
return new DefaultEntityResponseBuilder<>(producer,
|
||||
BodyInserters.fromProducer(producer, elementType))
|
||||
BodyInserters.fromProducer(producer, elementTypeRef))
|
||||
.status(this.statusCode)
|
||||
.headers(this.headers)
|
||||
.cookies(cookies -> cookies.addAll(this.cookies))
|
||||
|
@ -272,9 +272,9 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder {
|
|||
|
||||
@Override
|
||||
public <T, P extends Publisher<T>> Mono<ServerResponse> body(P publisher,
|
||||
ParameterizedTypeReference<T> elementType) {
|
||||
ParameterizedTypeReference<T> elementTypeRef) {
|
||||
return new DefaultEntityResponseBuilder<>(publisher,
|
||||
BodyInserters.fromPublisher(publisher, elementType))
|
||||
BodyInserters.fromPublisher(publisher, elementTypeRef))
|
||||
.status(this.statusCode)
|
||||
.headers(this.headers)
|
||||
.cookies(cookies -> cookies.addAll(this.cookies))
|
||||
|
|
|
@ -418,11 +418,11 @@ public interface ServerResponse {
|
|||
* @param producer the producer to write to the response. This must be a
|
||||
* {@link Publisher} or another producer adaptable to a
|
||||
* {@code Publisher} via {@link ReactiveAdapterRegistry}
|
||||
* @param typeReference a type reference describing the elements contained in the producer
|
||||
* @param elementTypeRef a type reference describing the elements contained in the producer
|
||||
* @return the built response
|
||||
* @since 5.2
|
||||
*/
|
||||
Mono<ServerResponse> body(Object producer, ParameterizedTypeReference<?> typeReference);
|
||||
Mono<ServerResponse> body(Object producer, ParameterizedTypeReference<?> elementTypeRef);
|
||||
|
||||
/**
|
||||
* Set the body of the response to the given asynchronous {@code Publisher} and return it.
|
||||
|
@ -441,13 +441,13 @@ public interface ServerResponse {
|
|||
* This convenience method combines {@link #body(BodyInserter)} and
|
||||
* {@link BodyInserters#fromPublisher(Publisher, ParameterizedTypeReference)}.
|
||||
* @param publisher the {@code Publisher} to write to the response
|
||||
* @param typeReference a type reference describing the elements contained in the publisher
|
||||
* @param elementTypeRef a type reference describing the elements contained in the publisher
|
||||
* @param <T> the type of the elements contained in the publisher
|
||||
* @param <P> the type of the {@code Publisher}
|
||||
* @return the built response
|
||||
*/
|
||||
<T, P extends Publisher<T>> Mono<ServerResponse> body(P publisher,
|
||||
ParameterizedTypeReference<T> typeReference);
|
||||
ParameterizedTypeReference<T> elementTypeRef);
|
||||
|
||||
/**
|
||||
* Set the body of the response to the given {@code BodyInserter} and return it.
|
||||
|
|
Loading…
Reference in New Issue