最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - Spring Restclient.exchange null response handling in spring 6.2.3 - Stack Overflow

programmeradmin0浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论