Xstream ignore field

to tell xtream don't read/write field to xml, make it transient.

to tell xtream ignore filed while reading xml, XStream xstream = new Xstream { protected MapperWrapper wrapMapper(MapperWrapper next) { return new MapperWrapper(next) { public boolean shouldSerializeMember(Class definedIn, String fieldName) { boolean r = definedIn != Object.class ? super.shouldSerializeMember(definedIn, fieldName) : false; if (!r) { System.out.println("field ignored:" + fieldName); }                        return r;                     } };            } };

How do I initialize a transient field at deserialization?

XStream uses the same mechanism as the JDK serialization. Example:

class ThreadAwareComponent { private transient ThreadLocal component; // ...  private Object readResolve { component = new ThreadLocal; return this; } } or

class ThreadAwareComponent { private transient ThreadLocal component; // ...  private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject; component = new ThreadLocal; } }