In my Android client, I get JSON data from the backend:
[ [ 1427378400000, 553 ], [ 1427382000000, 553 ] ]
Here is the procedure that actually loads the data. I use RxAndroid and Retrofit here.
private void getProductLevels() { Observable<List<List<Double>>> responseObservable = mProductService.readProductLevels(); AppObservable.bindFragment(this, responseObservable) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) // TODO: Transform List<List<Double>> into List<ProductLevel> .subscribe(new Subscriber<List<List<Double>>>() { @Override public void onCompleted() {} @Override public void onError(Throwable e) {} @Override public void onNext(List<List<Double>> response) {} }); }
How can I map an internal List<Double> to a specific Java class, such as ProductLevel , using RxJava statements ?
public class ProductLevel { public Double mTimeStamp; public Double mLevel; public ProductLevel(Double timeStamp, Double level) { mTimeStamp = timeStamp; mLevel = level; } }
Finally, I would like to get the following: List<ProductLevel> .
android retrofit rx-java rx-android observable
Jjd
source share