I am using retrofit to hit my network api which returns json array. I am doing so using following code-
Observable<MyJson[]> response = (Observable<MyJson[]>)mNetworkService.getReadyObserverable(mNetworkService.getNetworkServiceApi().getMyDataJsons(), MyJson.class, true, useCache);
mAirlineSubscription = response.subscribe(new Observer<MyJson[]>() {
@Override
public void onCompleted() {
Log.d(TAG, "getData completed..");
}
@Override
public void onError(Throwable e) {
Log.e(TAG, "onError: " + e.getLocalizedMessage());
}
@Override
public void onNext(MyJson[] myJsonData) {
//I want here json data one by one
}
But my problem is json data array get downloaded completely and then only
onNext gets called. Here I want onNext should get called when retrofit downloads first json object from myData[] json array and keep continue until my all json objects of myData[] get downloaded. This way my UI would look more responsive and better in terms of user interaction.
Can anyone help to fix this?
CallAdapterandConverterare needed. Both are required - in CallAdapter,ResponseBody's stream must be processed (get individual array items) AND converted to java objects, and Converter should just pass those results as is (noop). First, this contradicts retrofit's design, where CallAdapter and Converter are independent entities.Second, implementation would be nontrivial and lengthy - json streaming parsing, rxjava backpressure etc - i suggest you to find another solution to problem - data paging, smaller response etc