Search code examples
androidkotlinretrofitrx-android

Using custom converter with rxandroid Completable


I have a problem using retrofit with rxandroid. I've created a custom converter as below:

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

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

It's all working fine when i'm returning Single like this:

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

but when i try returning Completable like this:

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

I found that the convert function doesn't get call. Please help.

Thanks in advance.


Solution

  • For anyone who's running into the same case as me, apparently according to retrofit team here:

    Using Completable bypasses all converters, yes, and simply closes the response body so it is consumed. Since there is nowhere for the converted body to go with a Completable, there is no need to call it and perform conversion.

    So I guess we'll just keep using Single on this case.