public final class RxJava2CallAdapterFactory extends 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 errorsObservable<Result<User>>) calls onNext with a
Result object for all HTTP responses and errors.| Modifier and Type | Method and Description |
|---|---|
static RxJava2CallAdapterFactory |
create()
Returns an instance which creates synchronous observables that do not operate on any scheduler
by default.
|
static RxJava2CallAdapterFactory |
createAsync()
Returns an instance which creates asynchronous observables.
|
static RxJava2CallAdapterFactory |
createWithScheduler(io.reactivex.Scheduler scheduler)
Returns an instance which creates synchronous observables that
subscribe on
scheduler by default. |
CallAdapter<?,?> |
get(Type returnType,
Annotation[] annotations,
Retrofit retrofit)
Returns a call adapter for interface methods that return
returnType, or null if it
cannot be handled by this factory. |
getParameterUpperBound, getRawTypepublic static RxJava2CallAdapterFactory create()
public static RxJava2CallAdapterFactory createAsync()
Observable.subscribeOn(io.reactivex.Scheduler) has no effect on stream types created by this factory.public static RxJava2CallAdapterFactory createWithScheduler(io.reactivex.Scheduler scheduler)
scheduler by default.public CallAdapter<?,?> get(Type returnType, Annotation[] annotations, Retrofit retrofit)
CallAdapter.FactoryreturnType, or null if it
cannot be handled by this factory.get in class CallAdapter.FactoryCopyright © 2017 Square, Inc.. All rights reserved.