【问题标题】:Using custom converter with rxandroid Completable使用带有 rxandroid Completable 的自定义转换器
【发布时间】:2021-01-30 13:18:55
【问题描述】:

我在使用 rxandroid 进行改造时遇到问题。 我创建了一个自定义转换器,如下所示:

class CustomResponseConverter<T>(private val converter: Converter<ResponseBody, *>): Converter<ResponseBody, T> {

    override fun convert(value: ResponseBody): T? {
        // custom convert response here
    }
}

当我像这样返回Single 时一切正常:

@GET("route")
fun simpleFetch(): Single<FetchData>

但是当我尝试像这样返回Completable 时:

@GET("route")
fun simpleFetch(): Completable

我发现convert 函数没有被调用。请帮忙。

提前致谢。

【问题讨论】:

    标签: android kotlin retrofit rx-android


    【解决方案1】:

    对于遇到与我相同情况的任何人,显然根据改造团队here

    使用 Completable 会绕过所有转换器,是的,并且只是关闭响应主体以使其被消耗。由于转换后的主体无处可与 Completable 一起使用,因此无需调用它并执行转换。

    所以我想我们会在这个案例中继续使用Single

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-17
      • 2019-02-06
      • 2016-11-14
      • 1970-01-01
      相关资源
      最近更新 更多