Thank you Jörg.

I tried the two solutions, but unfortunately didn't work

I am doing some tests to see how annotation processing will be handled when
the "CustomerDTO" is within the same bundle. The surprise is it succeeded
only when I use :
  stream = new XStream();
            stream.processAnnotations(CustomerDTO.class);
It always failed when I set autodetectAnnotations to true (and remove
"processAnnotations(...)") even when I change Xstream's ClassLoader...

However I couldn't find a solution when I put CustomerDTO in a separated
bundle

Abdellah

2012/8/1 Jörg Schaible <[email protected]>

> 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