Hi,

Abdellah MERZOUK wrote:

> Hello,
> 
> I am using Xstream 1.4.2 to convert some xml input, it works perfectly in
> standard environment however when executed in OSGi context, annotations
> are simply ignored :
> 
>         XStream stream = new XStream();
>         stream.autodetectAnnotations(true);
>         stream.processAnnotations(CustomerDTO.class); // just in case...

This "just in case" will turn off auto detection again. See Javadoc.

> CustomerDTO is imported from another bundle, so I tried:
> 
> 
stream.processAnnotations(getClass().getClassLoader().loadClass(CustomerDTO.class.getName()));
> 
> But it didn't work :(
> 
> any suggestions ?

Personally I have no OSGi experience, but from reports of other users, I 
know that it can only work, if the classes are loaded with the appropriate 
bundle class loader.

Therefore you should set the appropriate class loader directly after XStream 
creation:


 XStream stream = new XStream();
 stream.setClassloader(bundleClassLoader);
 stream.autodetectAnnotations(true);


or you can meddle with XStream's internal CompositeClassLoader:

 XStream stream = new XStream();
 ((CompositeClassLoader)stream.getClassloader()).add(bundleClassLoader);
 stream.autodetectAnnotations(true);

- Jörg


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

    http://xircles.codehaus.org/manage_email


Reply via email to