users@jaxb.java.net

Re: CodeModel and nested annotations

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Wed, 11 Jun 2008 21:03:26 +0200

Hi.

> My thread got hijacked it seems :-(:-(

Pardon?

> Anyways, while on the question of annotations, is there anyway you can
> change the name of an @XmlElement at runtime. In other words, is there a way
> you can assign a string value to the 'name' attribute of @XmlElement?

You mean when generating the annotations with the code model or when
you've created a JAXB context from the annotated classes?
For the first case, add a parameter with the same name (and a
different value) - this will override previous definition.
If you mean the second case - this is also possible with some hacks
via reflection. You have to find the approriate "element property
info" and change its xmlName field.
For a less hacky way, write an own AnnotationReader (inherit from some
existing class) to return annotations with names as you need them.
Then use this reader to produce a JAXB context with customized element
(or whatever) names. Not very easy, but neither a rocket science.

Bye.
/lexi