在这个问题中How can I serialize a RealmObject to JSON in Realm for Java? Realm代表说可以通过GSON序列化Realm对象。你能解释一下怎么做吗? 我试过这个。
RealmResults<Dog> myDogs=realm.where(Dog.class).findAll();
new Gson().toJson(myDogs);
但是发生了StackOverflowError。
最佳答案
要使 GSON 序列化与 Realm 配合使用,您需要为每个可序列化的对象编写一个自定义 JsonSerializer,并将其注册为 TypeAdapter。
您可以在这个要点中看到一个示例:https://gist.github.com/cmelchior/ddac8efd018123a1e53a
关于json - 如何使用Gson库将RealmResult转换为Json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33014253/