when migrating from spring 6.1.5 to spring 6.2.3 I noticed in the RestClient interface that the the exchange method is now nullable. link to docs
How could you end up in a situation where Restclient returns null? Is the correct pattern now to have a default response when null is returned?
when migrating from spring 6.1.5 to spring 6.2.3 I noticed in the RestClient interface that the the exchange method is now nullable. link to docs
How could you end up in a situation where Restclient returns null? Is the correct pattern now to have a default response when null is returned?
Share Improve this question asked Mar 12 at 16:11 user406955user406955 891 silver badge11 bronze badges1 Answer
Reset to default 0By default, RestClient's retrieve()
never returns null
as it only proceeds to the declaration of how the response will be handled. The subsequently called methods body()
or exchange()
perform the call, and they return null
depending on the situation:
body()
returnsnull
if there is simply no response body available. A good example is HTTP204 NO CONTENT
status code.exchange()
returnsnull
ifExchangeFunction
returns it as well. You are in charge of its implementation by saying what happens with the response (also the request) is available. If your implementation returnsnull
, you got it.
The only explanation that makes sense to me is that the method contract documentation and annotation were fixed.