public final class RxJava3CallAdapterFactory
extends retrofit2.CallAdapter.Factory
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:
Observable<User>) calls onNext with the deserialized
body for 2XX responses and calls onError with HttpException for non-2XX
responses and IOException for network errors.
Observable<Response<User>>) calls onNext with
a Response object for all HTTP responses and calls onError with IOException for network errors
Observable<Result<User>>) calls onNext with a
Result object for all HTTP responses and errors.
| Modifier and Type | Method and Description |
|---|---|
static RxJava3CallAdapterFactory |
create()
Returns an instance which creates asynchronous observables that run on a background thread by
default.
|
static RxJava3CallAdapterFactory |
createSynchronous()
Returns an instance which creates synchronous observables that do not operate on any scheduler
by default.
|
static RxJava3CallAdapterFactory |
createWithScheduler(io.reactivex.rxjava3.core.Scheduler scheduler)
Returns an instance which creates synchronous observables that
subscribeOn(..) the
supplied scheduler by default. |
retrofit2.CallAdapter<?,?> |
get(java.lang.reflect.Type returnType,
java.lang.annotation.Annotation[] annotations,
retrofit2.Retrofit retrofit) |
public static RxJava3CallAdapterFactory create()
subscribeOn(..) has no effect on instances created by the returned
factory.public static RxJava3CallAdapterFactory createSynchronous()
subscribeOn(..) will change the scheduler on which the HTTP calls
are made.public static RxJava3CallAdapterFactory createWithScheduler(io.reactivex.rxjava3.core.Scheduler scheduler)
subscribeOn(..) the
supplied scheduler by default.@Nullable
public retrofit2.CallAdapter<?,?> get(java.lang.reflect.Type returnType,
java.lang.annotation.Annotation[] annotations,
retrofit2.Retrofit retrofit)
get in class retrofit2.CallAdapter.Factory