users@jaxb.java.net

Re: Re: Re: Re: Subclassing JAXB 2.0-generated classes

From: Dmitri Colebatch <dim_at_colebatch.com>
Date: Fri, 14 Jul 2006 07:46:02 +1000

Oh well, I'm all out. Feel free to send through a runnable test case
and I'd be interested to learn what the problem is.

cheers
dim

On 7/14/06, Pelenur, Matias <pelenur_at_amazon.com> wrote:
> unfortunately the exception happens even if the annotation is only on the accessor method, and not on the field. I've been modifying the generated class by hand at Kohsuke's suggestion, to try to get it to work so that we could then presumably work backwards to generate that code from the XJS.
>
> so the only way I've got it to work at this point is by removing the field completely, and having both accesor and setter methods, with the annotation on the accessor. But of course getting xjc to generate that is another issue altogether. perhaps this will require some changes in a future release of JAXB2.
>
> thanks for the suggestions,
> matias
>
> > -----Original Message-----
> > From: colebatchd_at_gmail.com [mailto:colebatchd_at_gmail.com] On
> > Behalf Of Dmitri Colebatch
> > Sent: Thursday, July 13, 2006 2:22 PM
> > To: users_at_jaxb.dev.java.net
> > Subject: Re: Re: Re: Subclassing JAXB 2.0-generated classes
> >
> > oh, sorry - I skimmed too quickly. I've always found those exception
> > messages to be very helpful.
> >
> > In the generated class, am I right that there is an annotation on the
> > field declaration _and_ on the field accessor method? Did you edit
> > the generated class by hand, or was it generated like this? If by
> > hand, then remove the annotation from the field. If it was generated
> > like that then it sounds like you've got you generation config wrong
> > (or you've hit some bug in xjc).
> >
> > I'm assuming you've edited the generated class by hand and the problem
> > is the presense of annotations on both the field and the method.
> >
> > cheers
> > dim
> >
> > On 7/14/06, Pelenur, Matias <pelenur_at_amazon.com> wrote:
> > > No, the annotation is only in the generated class, not in
> > the subclass.
> > >
> > > -matias
> > >
> > > > -----Original Message-----
> > > > From: colebatchd_at_gmail.com [mailto:colebatchd_at_gmail.com] On
> > > > Behalf Of Dmitri Colebatch
> > > > Sent: Thursday, July 13, 2006 2:03 PM
> > > > To: users_at_jaxb.dev.java.net
> > > > Subject: Re: Re: Subclassing JAXB 2.0-generated classes
> > > >
> > > > Am I right in assuming that you have the annotion on your
> > overriding
> > > > method in the subclass? If so, remove it.
> > > >
> > > > cheers
> > > > dim
> > > >
> > > > On 7/14/06, Pelenur, Matias <pelenur_at_amazon.com> wrote:
> > > > > 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
> > > > > >
> > > > >
> > > > >
> > > > >
> > > >
> > ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> > > > > For additional commands, e-mail: users-help_at_jaxb.dev.java.net
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> > > > For additional commands, e-mail: users-help_at_jaxb.dev.java.net
> > > >
> > >
> > >
> > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> > > For additional commands, e-mail: users-help_at_jaxb.dev.java.net
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> > For additional commands, e-mail: users-help_at_jaxb.dev.java.net
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>