0
votes

Hi i am using retrofit and rxjava to make a simple request and get the response back but it doesnt seem to be making the request itself or getting the response back?

This is my retrofit code:

public class Controller

 public Single<List<ListItems>> getItems() {
        return apiCall().getItems();
    }

    private ServiceCallsApiCall() {
        OkHttpClient okHttpClient = new OkHttpClient().newBuilder().addInterceptor(interceptor).build();
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .client(okHttpClient)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create()).build();

        ServiceCallsApiCall serviceCalls= retrofit.create(ServiceCallsApiCall.class);
        return foodHygieneServiceCalls;
    }

my ServiceCallsApiCall class

@GET("Authorities/basic")
    Single<List<ListItems>> getItems();

Here is my Rxjava part of my code that subscribes and observes this

  public void getItems() {
        new Controller().getItems()
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new SingleObserver<List<ListItems>>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        Log.d("","onSubscribe");
                    }

                    @Override
                    public void onSuccess(List<ListItems> items) {
                        viewPresenterCallBacks.updateView(items);
                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.d("","onError" + e.getMessage());
                    }
                });
    }

None of the onSuccess or onError gets called

1
What's apiCall() ? post code for it as well - elmorabea
@jonney did you resolve this issue ? - Gaurav Sarma

1 Answers

0
votes

I had a similar problem recently. The problem is not from retrofit or rxJava, its from the deserialization of the JSON to your ListItem POJO. I believe the crux of the issue is that your JSON deserialization library is unable to translate the Json to POJO.

If you are using Jackson you can just add the @JsonIgnoreProperties(ignoreUnknown = true) to your ListItem class.

In my case I was using GSON and since i wasn't interested in all the JSON properties I just changed my initial retrofit method signature from Single<Movies> getRecentMovies(); to Single<ResponseBody> getRecentMovies(); and extracted the desired fields in my response.