android - Saving complex objects to database using RxJava -


i have application makes requests 3rd party api , needs save of data local sqlite database (where local primary keys autoincremented).

those requests return json response contains many nested objects, need map , save , link record original parent object objecta in case.

{  "objectalist": [    {     "somefield1": "somevalue1",     "somefield2": "somevalue2",     "nestedobjectb": {         "nestedfield": "nestedvalue"      },      "nestedobjectcarray": [       {        "nestedarrayfield": "nestedarrayvalue"        }       ]      }     ]  } 

the app powered rxjava; i'm new to. (both networking , persistence via storio reactive). able set methods save in bulk parent objecta , works fine. run in issues start iterate though each of objects using observable.from , subsequently saving nested child objects, collecting records, , updating foreign keys in respective parent items (with usage of observable.zip multiple children). function executed (according logs anyway), somehow results don't submitted through rest of chain, i'm not sure if went wrong or if there's issue approach/implementation.

any or pointers on how appreciated!

edit sample psudeo-code added

/*this flatmap attached network request returns  defined json response*/  .flatmap(new func1<list<objectaresponse>, observable<list<objectaresponse>>>() {         @override         public observable<list<objectaresponse>> call(final list<objectaresponse> objectaresponse) {              return saveobjectalisttodb(someotherkey, objectajsonresponses)                                         .map(new func1<putresults<objectaentity>, list<objectaresponse>>() {                 @override                 public list<objectaresponse> call(putresults<objectaentity> putresults) {                 //returning original response nested values                 return objectaresponse;             }         });     } }) .flatmap(new func1<list<objectaresponse>, observable<objectaresponse>>() {             @override             public observable<objectaresponse> call(list<objectaresponse> objectaresponse) {                 //start emitting individual 'objecta' items process child items                 return observable.from(objectaresponse);             }         }) .flatmap(new func1<objectaresponse, observable<objectaentity>>() {                 @override                 public observable<objectaentity> call(objectaresponse objectaresponse) {                     /*saving individual nested objects in separate functions return observable contains                     * resultant entity updated in main objecta entity                     * (in reality there more nested child objects save in parallel)                     */                     return observable.zip(saveepic(objectaresponse.nestedobjectb), saveuser(objectaresponse.nestedobjectcarray),                          new func2<objectbentity, objectcentity, objectaentity>() {                          @override                         public object call(objectbentity objectbentity, objectcentity objectcentity) {                             //function updates initial object new entities                             return updateobjecta(objectaresponse.id, objectbentity, objectcentity);                         }                     });                 }             }) .collect(new func0<list<objectaentity>>() {                 @override                 public list<objectaentity> call() {                     return new arraylist<objectaentity>();                 }             },             new action2<list<objectaentity>, objectaentity>() {                 @override                 public void call(list<objectaentity> objectaentitylist, objectaentity o) {                     //collect resultant updated entities , return list                     objectaentitylist.add(o);                 }             }); 


Comments