Add ParameterizedTypeReference method variants to ServerRequest/ServerResponse

This commit changes adds overloaded `ParameterizedTypeReference `
variants to body-related methods in `ServerRequest` and
`ServerResponse`.
It also adds a single PTR variant to ClientRequest, which was missing
before.

Issue: SPR-15817
This commit is contained in:
Arjen Poutsma
2017-07-27 13:36:57 +02:00
parent c5fc400534
commit eb435f5947
12 changed files with 226 additions and 6 deletions

View File

@@ -33,6 +33,7 @@ import java.util.concurrent.ConcurrentHashMap;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpCookie;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
@@ -149,6 +150,13 @@ public class MockServerRequest implements ServerRequest {
return (Mono<S>) this.body;
}
@Override
@SuppressWarnings("unchecked")
public <S> Mono<S> bodyToMono(ParameterizedTypeReference<S> typeReference) {
Assert.state(this.body != null, "No body");
return (Mono<S>) this.body;
}
@Override
@SuppressWarnings("unchecked")
public <S> Flux<S> bodyToFlux(Class<? extends S> elementClass) {
@@ -156,6 +164,13 @@ public class MockServerRequest implements ServerRequest {
return (Flux<S>) this.body;
}
@Override
@SuppressWarnings("unchecked")
public <S> Flux<S> bodyToFlux(ParameterizedTypeReference<S> typeReference) {
Assert.state(this.body != null, "No body");
return (Flux<S>) this.body;
}
@Override
public Map<String, Object> attributes() {
return this.attributes;