How to convert the jsonStr to Observable<T> when use Retrofit

184 views Asked by At

I wrote a Interface for Retrofit,

public interface MyService {
    @POST("/api/index")
    <T> Observable<T> doRequest(@Body Object request);
}

then build the service,

RestAdapter restAdapter = new RestAdapter.Builder()
        .setEndpoint("http://localtest.com")
        .setConverter(new FastJsonConverter())
        .setRequestInterceptor(new CookiesInterceptor(LApplication.getInstance()))
        .build();
this.service = restAdapter.create(MyService.class);

when I do request:

Observable<Response> resp = service.doRequest(getRequest())
resp.subscribeOn(Schedulers.newThread())
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe(maoApi.mSubscriber);

but the converter cannot converjson to Response Object?

I print out the Type in FastJsonConverter:fromBody(TypedInput body, Type type) the type is T.

also when use Gson , is still has this problem...

How to solve this problem? or is my design is uncorrect?

0

There are 0 answers