Make XStream ignore one specific private variable

I have a little problem with the class in which I am currently writing a save function.

I am using XStream (com.thoughtworks.xstream) to serialize a class in XML using DOMDriver.

The class is as follows:

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

So the problem here is that I don’t want to serialize the configuration when serializing the world, instead I would like to provide an XStream with a pre-configured configuration instance when calling fromXml ().

The problem here is mainly in class design. The configuration contains a personal reference to the GUI classes, and therefore serializing the configuration means serializing the entire application using the graphical interface, etc. And this is bad.

Is there a way to instruct XStream not to serialize the private field configuration, but to use the configuration instance when loading XStream?

greetings Daniel

+7
java xstream
source share
1 answer

As the documentation says: http://x-stream.imtqy.com/annotations-tutorial.html (Omitting Fields), you can use the @XStreamOmitField annotation to ignore the fields.

+10
source share

All Articles