XStream 序列化集合 [英] XStream serializing collections

查看:32
本文介绍了XStream 序列化集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类结构,我想用 Xstream 对其进行序列化.根类包含其他对象(不同类型)的集合.我只想序列化存储在集合中的部分对象(主要是它们的 ID,而不是每个元素的剩余内容).

I have a class structure that I would like to serialize with Xstream. The root class contains a collection of other objects (of varying types). I would like to only serialize part of the objects that are stored in the collection (primarily their IDs, and not the remaining contents of each element).

有人知道我该怎么做吗?

Anyone have an idea of how I might go about this?

谢谢

推荐答案

可以指定除 ID 不应该被序列化:

  1. 声明它们transient
  2. 使用 @XStreamOmitField 注释它们
  3. 调用 xstream.omitField()

或者您可以编写自己的转换器.

这篇关于XStream 序列化集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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