I found this.
But in new ver compile 'com.squareup.retrofit2:adapter-rxjava:2.2.0'
at CallAdapter it has two params
CallAdapter<?,?>
How to modify RxCallAdapterWrapper to implement
if from CallAdapter<?,?>
I found this.
But in new ver compile 'com.squareup.retrofit2:adapter-rxjava:2.2.0'
at CallAdapter it has two params
CallAdapter<?,?>
How to modify RxCallAdapterWrapper to implement
if from CallAdapter<?,?>
Disclaimer: I'm the author of the blog post you referenced
The original post was meant as a proof of concept and for RxJava 2 so it's easier for me to explain with that version too, but I'll try and cover more ground. I'm guessing you're using version 1, since you talk about
adapter-rxjava
and notadapter-rxjava2
. That said, the implementation for version 1 should be pretty straight forward and just a matter of using the right imports.Here's what I've done using RxJava 2:
No major changes, just some playing around with return types. Now if you look at the
RxJava2CallAdapter
it implementsCallAdapter<R, Object>
, so we need to account for this.Then I've added some checks for the instance types to make sure we're returning the right things.
The really important part is to make sure you import the right packages. Retrofit adapters check for specific classes. One problem I had was having the wrong imports and had situations where I was checking if the
Throwable
was an instance ofcom.jakewharton.retrofit2.adapter.HttpException
, while it was actually an instance ofretrofit2.adapter.rxjava2.HttpException
.Hope this helps
Updated anwer of Fred to
kotlin
style andrxjava1:
com.squareup.retrofit2:adapter-rxjava:2.5.0
withio.reactivex:rxjava:1.3.8
RxErrorHandlingCallAdapterFactory.kt
RetrofitException.kt
rxjava2:
com.squareup.retrofit2:adapter-rxjava2:2.6.0
withio.reactivex.rxjava2:rxjava:2.2.9
RxErrorHandlingCallAdapterFactory.kt
RetrofitException.kt