users@jaxb.java.net

RE: Re: Subclassing JAXB 2.0-generated classes

From: Pelenur, Matias <pelenur_at_amazon.com>
Date: Thu, 13 Jul 2006 11:45:55 -0700

I tried moving the @XmlElement(name = "subElement") annotation from the field to the accesor method, but while unmarshalling an IllegalAnnotationsException is thrown (attached). There seems to be a conflict between having both the field and the accessor, even though the field does not have the annotation anymore.

If I comment-out the field and leave the accessor method only (with the annotation), then the unmarshaller ends up calling setSubElements() and passes it the list returned by getSubElements(), which seems a bit redundant. Other than that it seems to work.

--matias

> -----Original Message-----
> From: Kohsuke Kawaguchi [mailto:Kohsuke.Kawaguchi_at_Sun.COM]
> Sent: Wednesday, July 12, 2006 5:05 PM
> To: users_at_jaxb.dev.java.net
> Subject: Re: Subclassing JAXB 2.0-generated classes
>
> Pelenur, Matias wrote:
> > I see. Is there a way then to annotate the original XSD so that the
> > generated classes put the annotation on the method instead
> of the field?
>
> What makes this tricky is that it's not always possible to
> use methods.
> Sometimes methods have some side effect that interferes with
> marshalling/unmarshalling --- for example, "int getFoo()"
> might return a
> default value when no value is set.
>
> So this is hard to do in general.
>
> Maybe we can allow it to be configured per property by customization?
>
> Can you first check if moving annotation to the method would
> really work
> :-) ?
>
> --
> Kohsuke Kawaguchi
> Sun Microsystems kohsuke.kawaguchi_at_sun.com
>