Hi Ove, sounds weird at the first read. Do you have the sample code online 
somewhere?

LieGrue,
strub




----- Original Message -----
> From: Ove Ranheim <[email protected]>
> To: [email protected]
> Cc: 
> Sent: Sunday, September 2, 2012 2:38 PM
> Subject: Add JAXB annotations to a bean dynamically using the 
> AnnotatedTypeBuilder
> 
> Hi,
> 
> I'm trying to add JAXB annotations dynamically using the 
> AnnotatedTypeBuilder. My goal is to have a bean that is used to map data 
> using 
> JAXB (where I want to use my own annotations for declaration/mapping).
> 
> Extension:
> 
>     public <X> void processAnnotatedTypes(@Observes 
> ProcessAnnotatedType<X> processAnnotatedType) {
>         Class<X> beanClass = 
> processAnnotatedType.getAnnotatedType().getJavaClass();
>         
>         MyConfigSource myConfigSourceAnnotation = 
> beanClass.getAnnotation(MyConfigSource.class);
>         if (myConfigSourceAnnotation != null && 
> myConfigSourceAnnotation.location().length() > 0) {
>             
>             AnnotatedTypeBuilder<X> builder = new 
> AnnotatedTypeBuilder<X>().readFromType(beanClass);
>             builder.addToClass(new XmlRootElementLiteral());            
>             processAnnotatedType.setAnnotatedType(builder.create());          
>   
>             
>             log.infof("XmlRootElement annotation: %s", 
> builder.getJavaClass().getAnnotation(XmlRootElement.class)); <== return null
>         }
>         
>     }
> 
> My configuration bean:
> 
> @MyConfigSource(location = "parts.home")
> //@XmlRootElement(name = "parts-config")
> //@XmlAccessorType(XmlAccessType.PROPERTY)
> public class PartsXmlConfig implements Serializable {
>     ...
> }
> 
> 
> XmlRootElement literal:
> 
> public class XmlRootElementLiteral extends 
> AnnotationLiteral<XmlRootElement> implements XmlRootElement {
> 
>     private static final long serialVersionUID = 49878732553198946L;
> 
>     @Override
>     public String name() {
>         return "parts-config";
>     }
> 
>     @Override
>     public String namespace() {
>         return "http://www.w3.org/2001/XMLSchema";;
>     }
> 
> }
> 
> The compiler gives a warning that says: "The annotation type XmlRootElement 
> should not be used as a superinterface for XmlRootElementLiteral"
> 
> What is the correct way to use AnnotatedTypeBuilder in this case, and how can 
> I 
> get around the warning above for the XmlRootlElement?
> 
> 
> Best regards, 
> Ove
>

Reply via email to