【发布时间】:2017-10-28 06:49:48
【问题描述】:
我正在使用 Retrofit 2 调用一个微服务,该微服务在 PUT 方法上返回一个 200 和一个空响应体。
然而,改造 2 似乎无法处理这个问题,并且在“入队”中转到 onFailure 分支
@覆盖
public void onFailure(Call call, Throwable t) {
这里是日志:
Mai 27, 2017 3:26:49 PM okhttp3.internal.platform.Platform log
INFORMATION: --> PUT http://127.0.0.1/test/ http/1.1
Mai 27, 2017 3:26:49 PM okhttp3.internal.platform.Platform log
INFORMATION: Content-Type: application/vnd.tipico.notification-v1+json
Mai 27, 2017 3:26:49 PM okhttp3.internal.platform.Platform log
INFORMATION: Content-Length: 87
Mai 27, 2017 3:26:49 PM okhttp3.internal.platform.Platform log
INFORMATION:
Mai 27, 2017 3:26:49 PM okhttp3.internal.platform.Platform log
INFORMATION: {"state":"ACTIVE","externalId":"abcd","loginName":"gsdfgsdf","updatedAt":1495531062000}
Mai 27, 2017 3:26:49 PM okhttp3.internal.platform.Platform log
INFORMATION: --> END PUT (87-byte body)
Mai 27, 2017 3:26:50 PM okhttp3.internal.platform.Platform log
INFORMATION: <-- 200 http://127.0.0.1/test/ (197ms)
Mai 27, 2017 3:26:50 PM okhttp3.internal.platform.Platform log
INFORMATION: X-Application-Context: customer-care-notification-service:49980
Mai 27, 2017 3:26:50 PM okhttp3.internal.platform.Platform log
INFORMATION: Content-Length: 0
Mai 27, 2017 3:26:50 PM okhttp3.internal.platform.Platform log
INFORMATION: Date: Sat, 27 May 2017 13:26:49 GMT
Mai 27, 2017 3:26:50 PM okhttp3.internal.platform.Platform log
INFORMATION: <-- END HTTP (0-byte body)
15:26:50,030 ERROR com.test.app.Test - Failed CCNS call com.fasterxml.jackson.databind.JsonMappingException: No content to map due to end-of-input
at [Source: okhttp3.ResponseBody$BomAwareReader@9eb187b; line: 1, column: 0]
有人知道这是什么原因吗?由于请求已成功处理(见上文)。
【问题讨论】:
-
这很奇怪。您的调用是否返回任何改造可能尝试反序列化的对象?通过调用我的意思是 java 接口
-
您找到解决方案了吗?我面临同样的问题。看起来这发生在一些杰克逊版本中。您使用的是哪个版本?
-
嗨,是的,你需要像这里一样实现 NullOnEmptyConverterFactory github.com/square/retrofit/issues/1554
标签: retrofit retrofit2 okhttp3