我怎样才能在领域序列化RealmObject以JSON用于Java?领域、序列化、RealmObject、JSON

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

我在执行一个数据库为我的申请,我试图连接到我的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).

阅读全文

相关推荐

最新文章