Two things worth noting:
- XMLEncoder does not look at private fields. It only looks at matching pairs of 'get' and 'set' methods (or 'is' and 'set' methods). You have a
getNullableState
method but the set-method does not match; you should renamesetNullable
tosetNullableState
. - XMLEncoder only writes values for properties which are different from their initial state. The initial state of each property is whatever value it has when the object is initially constructed.
So, one way to force a property value to be written is to make sure it has a value that's different from what it had when the object was constructed.
If you want to always write XML for every property, you may want to consider using JAXB instead of XMLEncoder.