Ich benutze Realm mit Gson. Ich habe ein Modal, das eine Liste von Int-Typ-Feld hat. Der Realm unterstützt derzeit keine Liste von Primitiven. Um das zu lösen gibt es eine Lösung. Ich habe meine Klasse RealmInt erstellt.Gson Deserialisierung für Realm Liste von Primitiven
import io.realm.RealmObject;
public class RealmInt extends RealmObject {
private int val;
public int getVal() {
return val;
}
public void setVal(int val) {
this.val = val;
}
}
Ich habe ein großes modalen Objekt so ähnlich ..
public class Product extends RealmObject {
@PrimaryKey
private int productID;
private int priority;
private boolean isFavourite;
.....
.....
.....
private RealmList<Document> documents;
private RealmList<ProductInfoGroup> productInfoGroups;
private RealmList<RealmInt> categories;
ich die json Array unten an Produkt modals deserialisieren müssen.
[{
"productID": 776,
"categories": [
35
],
"name": "",
"priority": 3,
......
"status": 2,
"documents": [
{
"documentID": 74,
"productID": 776,
"name": null,
....
"isDefault": true
}
],
"productInfoGroups": [
{
"productInfoGroupID": 1575,
"productID": 776,
.....
"productInfos": [
{
"productInfoID": 2707,
"productInfoGroupID": 1575,
"title": "",
...
},
{
"productInfoID": 2708,
"productInfoGroupID": 1575,
...
},
{
"productInfoID": 2709,
.....
}
]
}
],
"lastUpdateDate": 130644319676570000,
"isActive": true
},....]
Es gibt eine Lösung here aber es ist nicht für große Objekte. Ich muss nur Kategorien Array ändern und andere Deserialisierung muss standardmäßig Gson Deserialisierung erfolgen.
Haben Sie die Lösung gefunden? – Hunt