users@jaxb.java.net

RE: injecting JAXB annotations at runtime

From: Reif, Benjamin <benjamin.reif_at_cgi.com>
Date: Tue, 9 Dec 2008 12:25:19 -0700

You can implement your own com.sun.xml.bind.v2.model.annotation.RuntimeAnnotationReader (which is really all JAXB introductions does to read the xml file instead of the annotations in the Class file). Your custom annotation reader can then do the necessary logic to return the correct annotation. Then you should be able to do something like this to hook it into JAXB:

 Map properties = new HashMap();

properties.put(JAXBRIContext.ANNOTATION_READER, new MyCustomRuntimeAnnotationReader());

 JAXBContext.getInstance(new Class[]{}, properties);

 

________________________________

From: Wolfgang Laun [mailto:wolfgang.laun_at_gmail.com]
Sent: Tuesday, December 09, 2008 1:47 PM
To: users_at_jaxb.dev.java.net
Subject: Re: injecting JAXB annotations at runtime

 

On Tue, Dec 9, 2008 at 6:56 PM, Arul Dhesiaseelan <arul_at_fluxcorp.com> wrote:

        Hi,
        
        I am trying to annotate a class with @XmlRootElement at runtime.



Although I may not be able to help you with this caper I'd still like to know why this has to be at runtime. There might be an altogether different approach, or can you exclude that?

 

        AFAIK, I can't use the JAXB introductions because it needs an external static configuration file.
        
        I can think of using javaassist to manipulate the class file at runtime. But, I wanted to check here if there is a better alternative to do this with any other tools or does JAXB RI provides any hooks to do this.
        
        -Arul