David Withers wrote:
> Alan Williams wrote:
>> David Withers wrote:
>> [snip]
>>
>> Hello,
>>
>>> 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.
>> What is happening? Are you saying that new fields are initialized to
>> null? If so, isn't a possible workaround for this to alter the
>> configuration bean so that when you do a getX it checks if x is null
>> and, if so, sets it to a value?
>
> If it's a new field that's not in the serialized file then yes, it's
> initialized to null, even though I'm setting a value when I declare the
> field, e.g. private String csvDelimiter = ",";
>
> So yes, the workaround in this case is:
>
> public String getCsvDelimiter() {
> return outputFormat == null ? "," : csvDelimiter;
> }
>
>
>>> If you add an enum field then an exception is thrown (which is the
>>> problem I'm hitting).
>> What is throwing the exception?
>
> XStream. I'm guessing that it creates to object for the field and then
> sets the value from the serialized xml. However you can't create enums
> without knowing the value.
Actually I'm wrong there. It seems that because the class is created
without calling a constructor any values that appear to be assigned as
part of the field declaration actually aren't assigned.
Oh well, at least I have a workaround now.
David.
--
David Withers
School of Computer Science, University of Manchester,
Oxford Road, Manchester, M13 9PL, UK.
+44 (0)161 275 0683
------------------------------------------------------------------------------
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