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


Reply via email to