android 有没有可以管理循环引用的json 库?
android 是否有可以管理循环引用的 json 库?我需要序列化一个包含对象列表的对象,其中列表中的每个对象都可以包含自身类型的对象列表。
例如,
class item{
LinkedList<item> list
}
class container{
LinkedList<item> list;
}
我尝试过使用 Gson (和 Xtreme to xml ),但它不起作用。
Is there any json library for android which can manage circular reference ? I need to serialize one object which contains list of objects, where every object from list can contains list of objects of self type.
for example
class item{
LinkedList<item> list
}
class container{
LinkedList<item> list;
}
I have tried with Gson ( and Xtreme to xml ) but it doesn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Android 将运行您选择的任何 Java 库。
AFAIK,Gson 不处理循环引用,但 Jackson 和 XStream 可以。
查看这些线程以获取更多信息:
如何解决hibernate双向映射导致的json序列化器循环引用?
杰克逊与杰克逊Gson
UPD 但是您最好向这些反向引用添加忽略注释。
Android will run whatever Java library you choose.
AFAIK, Gson doesn't handle circular references, but Jackson and XStream do.
Check out these threads for further info:
How to solve circular reference in json serializer caused by hibernate bidirectional mapping?
Jackson Vs. Gson
UPD But you're probably better off adding ignore annotations to those back references.