android - Using Retrofit and GreenDao with nested json objects -


i want combine retrofit , greendao have problem nested json-objects. nested fields remain empty.

this json datastructure

[     {         "id": 1,          "street": "streetname",          "zipcode": 12345,          "city": "mycity",          "phone_number": "+123456789",          "position": "12.0000, 9.0000",          "company": {             "title": "companyname",              "group": {                 "title": "groupname"             }         }     } ] 

my daogenerator looks this

    entity customitem = schema.addentity("customitems");     customitem.addidproperty();     customitem.addstringproperty("street");     customitem.addintproperty("zipcode");     customitem.addstringproperty("city");     customitem.addstringproperty("phone_number");     customitem.addstringproperty("position");      entity company = schema.addentity("company");     company.addidproperty();     company.addstringproperty("title");      entity group = schema.addentity("group");     group.addidproperty();     group.addstringproperty("title");      property companypropid = customitem.addlongproperty("companyid").notnull().getproperty();     customitem.addtoone(company, companypropid);      property grouppropid = company.addlongproperty("groupid").notnull().getproperty();     company.addtoone(group, grouppropid); 

my problem customitem.getcompany() returns null values "id" "position" fine. i'm not sure problem customitem class contains member

private company company; 

and setter company , can't see typo.

public void setcompany(company company) {     if (company == null) {         throw new daoexception("to-one property 'companyid' has not-null constraint; cannot set to-one null");     }     synchronized (this) {         this.company = company;         companyid = company.getid();         company__resolvedkey = companyid;     } } 

i got running had multiple problems.

1) when wanted persist customitem, company, , group had problem getters getcompany() , getgroup() returned null because don't return member directly fetch db. therefore added getter generated customitem entity class returns company member. able insert company db. getter looks this:

// keep methods - put custom methods here public company getcompanylocal() {     return company; } // keep methods end 

the same works company , group, too. there issue...

2) second problem entity 'group' 'group' reserved sql keyword. see 1 solution , bad workaround problem:

  • the 1 change json data 'group' i.e. 'business_group' , according change daos. done.

  • the bad workaround if in same situation me can't change json following. don't persist group @ can access via company. somehow appears there. therefore added getter company class getter of customitem above. works should avoid this. can't query db group or load group db.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -