Use IntrospectingClientHttpResponse in RestClient

This commit ensures that the RestClient uses the
IntrospectingClientHttpResponse to verify whether the response has a
body, and return null if it does not.

See gh-12671
Closes gh-31719
This commit is contained in:
Arjen Poutsma
2023-12-01 14:22:58 +01:00
parent 0dbb0f5c14
commit d204dd2dbe
2 changed files with 33 additions and 5 deletions

View File

@@ -348,6 +348,23 @@ class RestClientIntegrationTests {
assertThat(result).isNull();
}
@ParameterizedRestClientTest
@SuppressWarnings({ "rawtypes", "unchecked" })
void retrieveJsonEmpty(ClientHttpRequestFactory requestFactory) {
startServer(requestFactory);
prepareResponse(response -> response
.setResponseCode(200)
.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE));
Pojo result = this.restClient.get()
.uri("/null")
.retrieve()
.body(Pojo.class);
assertThat(result).isNull();
}
@ParameterizedRestClientTest
void retrieve404(ClientHttpRequestFactory requestFactory) {
startServer(requestFactory);