我怎样才能在领域序列化RealmObject以JSON用于Java? [英] How can I serialize a RealmObject to JSON in Realm for Java?

查看:993
本文介绍了我怎样才能在领域序列化RealmObject以JSON用于Java?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在执行一个数据库为我的申请,我试图连接到我的REST接口。该数据来自于为JSON,并使用新的JSON支持(如域0.76),我可以扔JSON在我的 Realm.createObjectFromJson(MyType.class,jsonString)和它创建此时,相应的obejcts和RealmLists。

I am implementing a DB for my Application and I am trying "connect" it to my REST interface. The data comes in as JSON and with the new JSON-Support (as of Realm 0.76) I can throw the JSON at my Realm.createObjectFromJson(MyType.class, jsonString) and it creates the appropiate obejcts and RealmLists.

但我怎么能反其道而行之?也就是说,采取RealmObject并将其序列化到JSON?它也应该序列化对象中的任何RealmList。

But how can I do the opposite? That is, take a RealmObject and serialize it to JSON? It also should serialize any RealmList inside that object.

推荐答案

从境界这里的基督徒。 境界为Android目前没有任何这样的方法,虽然在核心数据库实际上支持JSON序列化,所以现在你要么做手工或使用像GSON(警告第三方工具,我没有带测试的情景还)。

Christian from Realm here. Realm for Android currently doesn't have any such methods, although the core database actually supports JSON serialisation, so for now you would either have to do it manually or use a 3rd party tool like GSON (caveat, I havn't tested that scenario yet).

这篇关于我怎样才能在领域序列化RealmObject以JSON用于Java?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆