Package hu.akarnokd.rxjava3.retrofit
Class RxJava3CallAdapterFactory
- java.lang.Object
-
- retrofit2.CallAdapter.Factory
-
- hu.akarnokd.rxjava3.retrofit.RxJava3CallAdapterFactory
-
public final class RxJava3CallAdapterFactory extends retrofit2.CallAdapter.FactoryA call adapter which uses RxJava 3 for creating observables.Adding this class to
Retrofitallows you to return anObservable,Flowable,Single,CompletableorMaybefrom service methods.
There are three configurations supported for theinterface MyService { @GET("user/me") Observable<User> getUser() }Observable,Flowable,Single,CompletableandMaybetype parameter:- Direct body (e.g.,
Observable<User>) callsonNextwith the deserialized body for 2XX responses and callsonErrorwithHttpExceptionfor non-2XX responses andIOExceptionfor network errors. - Response wrapped body (e.g.,
Observable<Response<User>>) callsonNextwith aResponseobject for all HTTP responses and callsonErrorwithIOExceptionfor network errors - Result wrapped body (e.g.,
Observable<Result<User>>) callsonNextwith aResultobject for all HTTP responses and errors.
- Direct body (e.g.,
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static RxJava3CallAdapterFactorycreate()Returns an instance which creates synchronous observables that do not operate on any scheduler by default.static RxJava3CallAdapterFactorycreateAsync()Returns an instance which creates asynchronous observables.static RxJava3CallAdapterFactorycreateWithScheduler(Scheduler scheduler)Returns an instance which creates synchronous observables that subscribe onschedulerby default.@Nullable retrofit2.CallAdapter<?,?>get(java.lang.reflect.Type returnType, java.lang.annotation.Annotation[] annotations, retrofit2.Retrofit retrofit)
-
-
-
Method Detail
-
create
public static RxJava3CallAdapterFactory create()
Returns an instance which creates synchronous observables that do not operate on any scheduler by default.- Returns:
- the new adapter instance
-
createAsync
public static RxJava3CallAdapterFactory createAsync()
Returns an instance which creates asynchronous observables. ApplyingObservable.subscribeOn(io.reactivex.rxjava3.core.Scheduler)has no effect on stream types created by this factory.- Returns:
- the new adapter instance
-
createWithScheduler
public static RxJava3CallAdapterFactory createWithScheduler(Scheduler scheduler)
Returns an instance which creates synchronous observables that subscribe onschedulerby default.- Parameters:
scheduler- the scheduler to run the network operations on- Returns:
- the new adapter instance
-
-