Fix RestClient generic type handling
For client side use case, the context class should be null, consistently with what is done in HttpMessageConverterExtractor. Closes gh-31574
This commit is contained in:
@@ -63,6 +63,7 @@ import static org.junit.jupiter.api.Named.named;
|
||||
* Integration tests for {@link RestClient}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
class RestClientIntegrationTests {
|
||||
|
||||
@@ -179,6 +180,29 @@ class RestClientIntegrationTests {
|
||||
});
|
||||
}
|
||||
|
||||
@ParameterizedRestClientTest
|
||||
void retrieveJsonWithListParameterizedTypeReference(ClientHttpRequestFactory requestFactory) {
|
||||
startServer(requestFactory);
|
||||
|
||||
String content = "{\"containerValue\":[{\"bar\":\"barbar\",\"foo\":\"foofoo\"}]}";
|
||||
prepareResponse(response -> response
|
||||
.setHeader("Content-Type", "application/json").setBody(content));
|
||||
|
||||
ValueContainer<List<Pojo>> result = this.restClient.get()
|
||||
.uri("/json").accept(MediaType.APPLICATION_JSON)
|
||||
.retrieve()
|
||||
.body(new ParameterizedTypeReference<ValueContainer<List<Pojo>>>() {});
|
||||
|
||||
assertThat(result.containerValue).isNotNull();
|
||||
assertThat(result.containerValue).containsExactly(new Pojo("foofoo", "barbar"));
|
||||
|
||||
expectRequestCount(1);
|
||||
expectRequest(request -> {
|
||||
assertThat(request.getPath()).isEqualTo("/json");
|
||||
assertThat(request.getHeader(HttpHeaders.ACCEPT)).isEqualTo("application/json");
|
||||
});
|
||||
}
|
||||
|
||||
@ParameterizedRestClientTest
|
||||
void retrieveJsonAsResponseEntity(ClientHttpRequestFactory requestFactory) {
|
||||
startServer(requestFactory);
|
||||
|
||||
Reference in New Issue
Block a user