Package retrofit2.adapter.rxjava3
Class RxJava3CallAdapterFactory
java.lang.Object
retrofit2.CallAdapter.Factory
retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory
public final class RxJava3CallAdapterFactory
extends retrofit2.CallAdapter.Factory
A call adapter which uses RxJava 3 for creating observables.
Adding this class to Retrofit allows you to return an Observable, Flowable, Single, Completable or Maybe from service methods.
interface MyService {
@GET("user/me")
Observable<User> getUser()
}
There are three configurations supported for the Observable, Flowable,
Single, Completable and Maybe type 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.
-
Method Summary
Modifier and Type Method Description static RxJava3CallAdapterFactorycreate()Returns an instance which creates asynchronous observables that run on a background thread by default.static RxJava3CallAdapterFactorycreateSynchronous()Returns an instance which creates synchronous observables that do not operate on any scheduler by default.static RxJava3CallAdapterFactorycreateWithScheduler(io.reactivex.rxjava3.core.Scheduler scheduler)Returns an instance which creates synchronous observables thatsubscribeOn(..)the suppliedschedulerby default.retrofit2.CallAdapter<?,?>get(java.lang.reflect.Type returnType, java.lang.annotation.Annotation[] annotations, retrofit2.Retrofit retrofit)
-
Method Details
-
create
Returns an instance which creates asynchronous observables that run on a background thread by default. ApplyingsubscribeOn(..)has no effect on instances created by the returned factory. -
createSynchronous
Returns an instance which creates synchronous observables that do not operate on any scheduler by default. ApplyingsubscribeOn(..)will change the scheduler on which the HTTP calls are made. -
createWithScheduler
public static RxJava3CallAdapterFactory createWithScheduler(io.reactivex.rxjava3.core.Scheduler scheduler)Returns an instance which creates synchronous observables thatsubscribeOn(..)the suppliedschedulerby default. -
get
@Nullable public retrofit2.CallAdapter<?,?> get(java.lang.reflect.Type returnType, java.lang.annotation.Annotation[] annotations, retrofit2.Retrofit retrofit)- Specified by:
getin classretrofit2.CallAdapter.Factory
-