Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / JavaBeans / March 2006

Tip: Looking for answers? Try searching our database.

Java Bean properties not serializing default values

Thread view: 
wizofaus@hotmail.com - 28 Mar 2006 00:15 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.