简体   繁体   English

序列化为json字符串或二进制

[英]Serialize as json string or binary

I need to persist a object. 我需要坚持一个对象。 Unfortunately sqlite in android does not support ORM. 不幸的是,Android中的sqlite不支持ORM。 Therefore I need to choose a different way to persist my data. 因此,我需要选择其他方式来保留数据。

Is it better to persist the data via java serialization (ObjectOutputStream) within a blob, or via Gson's json serialization as a json string? 通过blob内的java序列化(ObjectOutputStream)或通过Gson的json序列化作为json字符串来持久存储数据是否更好? Afterwards I need to serialize the data again as a json string in order to transmit it to a restful wcf service. 之后,我需要再次将数据序列化为json字符串,以便将其传输到一个宁静的wcf服务。

I'm worried about the serialization speed because afaik working with strings isn't very efficient. 我担心序列化速度,因为afaik处理字符串不是很有效。

In my experience serialization works faster than gson, but I haven't done any test on it. 以我的经验,序列化比gson更快,但是我还没有做任何测试。 If speed is of concern I'd recommend you to do that test yourself. 如果您担心速度,我建议您自己进行测试。

On another note, you can use ORM on java/Android, read here: Any good ORM tools for Android development? 另外,您可以在Java / Android上使用ORM,请阅读此处: 是否有用于Android开发的好的ORM工具?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM