If a class has a default value for a particular property, even if you
explicitly in the code set the value to that same value, e.g.
public class MyBean
{
private int prop = 42;
void setProp(int p) { prop = p; }
int getProp() { return prop; }
};
...
MyBean bean = new MyBean();
bean.setProp(42);
then it appears the property value will not get serialized (at least,
using the XMLEncoder).
Only if the value is different to the default value assigned in the
class definition will it be saved.
I've checked and rechecked this, and I'm 100% sure this is what is
occurring.
But this is quite unacceptable, as the default value in the code may
well change in the future - but I don't want old files to suddenly be
interpreted differently. Is there a way to ensure that *all* property
values are written, no matter if they are the same as the default
values?
Thanks,
Dylan
wizofaus@hotmail.com - 28 Mar 2006 00:54 GMT
Never mind, I found out how to get around this (setting the "transient"
property to false). Still, kind of annoying.
wizofaus@hotmail.com - 28 Mar 2006 05:13 GMT
Ok, do mind - that doesn't work. Supposedly you can fix this problem
using XMLEncoder.setPersistenceDelegate() but I couldn't get it to
work.