我的 JSON 数据从服务器 api 看起来像这样
{
//...
PredecessorIds:[[1,2][3,4][5]]
//...
}
我可以成功处理 Integer 或 String 的数组,RealmList<RealmInt>
但是这次我失败了,因为 RealmList> 不支持说,"Type parameter 'io.realm.realmList' is not within its bounds...."
请RealmInt
参阅此链接。
我尝试使用RealmList<RealmLista>
RealmLista 扩展的地方来解决它,RealmObject
并且有RealmList
这样的
public class RealmLista extends RealmObject {
public RealmList<RealmInt> value;
public RealmLista() {
}
public RealmLista(RealmList<RealmInt> val) {
this.value = val;
}
}
然后创建 aRealmListaTypeAdapter
并将其添加到 Gson 但在反序列化时Gson expects an Object (RealmLista) but is found array
,如上面显示的来自服务器的数据是显而易见的。
//RealmListAdapter for Gson
@Override
public RealmLista read(JsonReader in) throws IOException {
RealmLista lista = new RealmLista();
Gson gson = new Gson();
//how to read that [[1],[3,4]] int into RealmLista
in.beginArray();
while (in.hasNext()) {
lista.value.add(new RealmInt(in.nextInt()));
}
in.endArray();
return lista;
}
有什么方法可以在保存的同时List<List<Integer>>
转换为RealmObject
任何类型来存储简单List<List<Integer>>
,Gson很容易转换。:-/