Reputation: 73
I am having an issue getting all of my POJOs and everything setup so that it parses my JSON correctly.
I am fairly new to Android development so the fix could be something simple.
I was able to get this to work without Realm. I think modified my POJOs to extend RealmObject. My issue is with my relationships. My data is setup so I have a WorkOrder class and a WorkOrderItem class. A WorkOrder contains many WorkOrderItems. Without realm I define this in my POJO as
private List<WorkOrderItem> workOrderItems = new ArrayList<WorkOrderItem>();
When I modify this to extend a RealmObject I start running into issue. I have tried
private RealmList<WorkOrderItem> workOrderItems;
As well as
private RealmList<WorkOrderItem> workOrderItems = new RealmList<WorkOrderItem>();
Either way I continue to receive the following error:
Error:(831, 82) error: incompatible types: List<WorkOrderItem> cannot be converted to RealmList<WorkOrderItem>
I have setup my GsonConverter as suggested in the documentation.
I have read through all of the documentation and everything I can find online and still have not found a solution. Any help on this would be greatly appreciated.
Upvotes: 0
Views: 1115
Reputation: 5505
On request the callback you're probably getting a List <WorkOrderItem>
So I think you need to create your Realmlist <WorkOrderItem>
from your list.
you need have two Objects WorkOrderItem
and other WorkOrderItemRealm extends RealmObject
For instance :
List<WorkOrderItem> mWorkOrderList...
RealmList<WorkOrderItem> mRealmList... //WorkOrderItem need to be a RealmObject
...new Callback<List<WorkOrderItem> mWorkOrderList>() {
@Override
public void success(List<WorkOrderItem> mWorkOrderList, Response response) {
for(WorkOrderItem mWorkOrderItem : mWorkOrderList){
//create WorkOrderItemRealm
WorkOrderItemRealm mWorkOrderItemRealm = realm.createObject(WorkOrderItemRealm.class);
//mWorkOrderItemRealm.set...(mWorkOrderItem.get...());
mRealmList.add(WorkOrderItemRealm);
}
}
@Override
public void failure(RetrofitError error) {
}
});
Upvotes: 2