Make XStream ignore one specific private variable

Posted by Tigraine on Stack Overflow See other posts from Stack Overflow or by Tigraine
Published on 2010-05-08T18:16:24Z Indexed on 2010/05/08 18:18 UTC
Read the original article Hit count: 244

Filed under:
|

Hi guys, 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

© Stack Overflow or respective owner

Related posts about java

Related posts about xstream