[xstream-user] deserializing null problem

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[xstream-user] deserializing null problem

Jeremy Moore
Hi

I have a problem when deserializing null elements. Can anyone please
help?

When I use xtream to serialise an object containing an instance variable
with a null value to produces the something like the following example:
...
<action>
      <date>2005-10-25 21:32:38.838 EST</date>
      <null/>
      <string>Do some action</string>
        ...
</action>
...

The second element is null which is fine.  

The problem is that when this is de-serialized I get:

com.thoughtworks.xstream.converters.ConversionException: null
---- Debugging information ----
required-type       : tr.model.action.Action
cause-message       : null
class               : tr.model.Data
line number         : 184
path                : /data/actionManager/action/null
cause-exception     : java.lang.NullPointerException
-------------------------------
        at
com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:45)
...

Do I need to do something special just to allow null values?

Thanks in advance.
Jeremy

Reply | Threaded
Open this post in threaded view
|

Re: [xstream-user] deserializing null problem

Jeremy Moore
Sorry to bother you I found the problem.

My classes were implementing Externalizable (as that is how I was
serializing) and writing the object instance variables. XStream then
serialized those values and not the class instance.  

Jeremy


On Sat, 2005-10-29 at 10:35 +1000, Jeremy Moore wrote:

> Hi
>
> I have a problem when deserializing null elements. Can anyone please
> help?
>
> When I use xtream to serialise an object containing an instance variable
> with a null value to produces the something like the following example:
> ...
> <action>
>       <date>2005-10-25 21:32:38.838 EST</date>
>       <null/>
>       <string>Do some action</string>
> ...
> </action>
> ...
>
> The second element is null which is fine.  
>
> The problem is that when this is de-serialized I get:
>
> com.thoughtworks.xstream.converters.ConversionException: null
> ---- Debugging information ----
> required-type       : tr.model.action.Action
> cause-message       : null
> class               : tr.model.Data
> line number         : 184
> path                : /data/actionManager/action/null
> cause-exception     : java.lang.NullPointerException
> -------------------------------
> at
> com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:45)
> ...
>
> Do I need to do something special just to allow null values?
>
> Thanks in advance.
> Jeremy
>