On Wed, Sep 30, 2009 at 02:00, David Withers <[email protected]> wrote:
> After investigating some more I've found that although the XStream docs > say "If a new field is added to the class, deserializing an old version > will leave the field uninitialized", this is not the case. String fields > are initialized to null, even if you set a default value for the field. > If you add an enum field then an exception is thrown (which is the > problem I'm hitting). You are right, we got this same problem when trying to extend the caGrid activity. The reason is that xstream is loading the bean in the same way as Java serialisation, so it's not using the constructors. What you need to do is unfortunately to do lots of null-checks in each of the getMyProperty() methods - and move the defaults in there. (To avoid confusion I would then let the constructors set the fields to null) Likweise, if you need to remove a property, to support loading of old beans, all you need to do is keep around a field: private transient String blah; .. you don't need the get/set methods, as the xstream only uses the fields directly. As it's transient it would not be saved later. (Use transient depending on if you want the bean to survive a trip through a new version of your plugin and then loaded up in the old plugin again) Obviously, a better serialization framework (open for suggestions for scufl2, although it currently seems we're moving towards a simpler property-value-pair mechanism - JSON-like) would use the beans directly as beans (calling getters and setters), and use the normal constructors. -- Stian Soiland-Reyes, myGrid team School of Computer Science The University of Manchester ------------------------------------------------------------------------------ Come build with us! The BlackBerry® Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9-12, 2009. Register now! http://p.sf.net/sfu/devconf _______________________________________________ taverna-hackers mailing list [email protected] Web site: http://www.taverna.org.uk Mailing lists: http://www.taverna.org.uk/taverna-mailing-lists/ Developers Guide: http://www.mygrid.org.uk/tools/developer-information
