Make XStream ignore one specific private variable

倖福魔咒の 提交于 2019-12-12 09:38:56

问题


I have a little problem with a class I am currently writing a save function for.

I'm using XStream (com.thoughtworks.xstream) to serialize a class to XML using the DOMDriver.

The class looks like this:

public class World {
  private Configuration config;
  public World(Configuration config) {
     this.config = config;
  }
}

So, the issue here is that I do not want to serialize Configuration when serializing world, rather I'd like to give XStream a preconstructed Configuration instance when calling fromXml().

Problem here is mainly class design, Configuration holds a private reference to the GUI classes and therefore serializing Configuration means serializing the whole application completely with GUI etc.. And that's kind of bad.

Is there a way to instruct XStream to not serialize the private field config, and upon load supply XStream with a configuration instance to use?

greetings Daniel


回答1:


As documentation says here: http://x-stream.github.io/annotations-tutorial.html (Omitting Fields) you can use @XStreamOmitField annotation to "ignore" fields.



来源:https://stackoverflow.com/questions/2795138/make-xstream-ignore-one-specific-private-variable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!