NPE with @XStreamAsAttribute annotation on generics during serialization

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

NPE with @XStreamAsAttribute annotation on generics during serialization

Zschorn, Andreas

Hi guys,

 

We are using xstream quite heavily and  have an surprising blocker, while updating from xstream 1.3.1 to 1.4.6 in order to make our application java 7 ready.

 

The annotation @XStreamAsAttribute does not work with generics anymore, it results in an NPE during serialization to XML. It was working with 1.3.1

 

com.thoughtworks.xstream.converters.reflection.SerializationMethodInvoker.getMethod(SerializationMethodInvoker.java:161)

 

Has anyone experienced something similar, or knows an workaround.

I could not find anything in jira.

I created an ticket for it and attached an example project with testcases.

 

http://jira.codehaus.org/browse/XSTR-753

This is an quite big blocker for us. Does anyone has an hint, what is going wrong.

 

Thanks for your input.

Best regards

 

Andreas Zschorn
________________________________________
zeb/information.technology gmbh & co. kg

Hammer Straße 165
48153 Münster

Phone 

+4925197128593

Fax 

+4925197128-101

E-Mail 

[hidden email]

WWW 

http://www.zeb.de




Amtsgericht Münster | HRA 5127
Geschäftsführer: Martin Danne | Jürgen Hofner | Andreas Schick

 


Diese E-Mail und alle angefügten Dateien sind vertraulich und ausschließlich für den Adressaten bestimmt. Sollten Sie nicht der bezeichnete Adressat sein, informieren Sie bitte umgehend den Absender. Die Inhalte dieser E-Mail dürfen in diesem Fall nicht an Dritte weitergegeben, für keine Zwecke genutzt und in keiner Form gespeichert oder kopiert werden. Im Fall technischer Probleme mit dieser E-Mail wenden Sie sich bitte an den Absender.

This e-mail and any attachments are confidential and may also be privileged. If you are not the named recipient, please notify the sender immediately and do not disclose the contents to another person, use it for any purpose, or store or copy the information in any medium. In the event of any technical difficulty with this e-mail, please contact the sender.

Reply | Threaded
Open this post in threaded view
|

Re: NPE with @XStreamAsAttribute annotation on generics during serialization

Jörg Schaible-2
Hi Andreas,

Zschorn, Andreas wrote:

> Hi guys,
>
> We are using xstream quite heavily and  have an surprising blocker, while
> updating from xstream 1.3.1 to 1.4.6 in order to make our application java
> 7 ready.
>
> The annotation @XStreamAsAttribute does not work with generics anymore, it
> results in an NPE during serialization to XML. It was working with 1.3.1
>
>
com.thoughtworks.xstream.converters.reflection.SerializationMethodInvoker.getMethod(SerializationMethodInvoker.java:161)
>
> Has anyone experienced something similar, or knows an workaround.
> I could not find anything in jira.
> I created an ticket for it and attached an example project with testcases.
>
> http://jira.codehaus.org/browse/XSTR-753
> This is an quite big blocker for us. Does anyone has an hint, what is
> going wrong.

It works for normal generic parameters, but not for bounded ones, I'll have
to investigate. However, the field cannot be written as attribute anymore!

See:

=============== %< ================
 class X {
   @XStreamAsAttribute
   String s;
 }
 X x = new X();
 x.s="value";
 system.out.println(new XStream().toXML(x));
=============== %< ================

this will be written as:

=============== %< ================
 <X s="value"/>
=============== %< ================

However, it is different for this class:

=============== %< ================
 class Y<T> {
   @XStreamAsAttribute
   T s;
 }
 Y<String> y = new Y<String>();
 y.s="value";
 system.out.println(new XStream().toXML(y));
=============== %< ================

XML will be written as:

=============== %< ================
 <Y>
   <s class="string">value</s>
 </Y>
=============== %< ================

The class contains an Object as field type as a result of the type erasure.
Since type of the instance does not match type of the field, no attribute
can be generated for the field. You will have to write a custom converter.

I will have to take a closer look though, why this NPE occurs if the generic
parameter type is bounded. Stay tuned.

Regards,
Jörg


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email