admin管理员组

文章数量:1389873

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

By 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() returns null if there is simply no response body available. A good example is HTTP 204 NO CONTENT status code.

  • exchange() returns null if ExchangeFunction 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 returns null, you got it.

The only explanation that makes sense to me is that the method contract documentation and annotation were fixed.

本文标签: javaSpring Restclientexchange null response handling in spring 623Stack Overflow