users@jaxb.java.net

Re: subclasses, annotation inheritance and propOrder

From: Sekhar Vajjhala <Sekhar.Vajjhala_at_Sun.COM>
Date: Wed, 22 Jun 2005 13:49:23 -0400

Dmitri Colebatch wrote:

>Hi again,
>
>Simpler problems now, although I'm pretty confident this is a bug of
>some sort. In short - if I have a subclass that wants to change the
>propOrder I'm finding that either I cant do it (if I include the
>superclasses properties I get a "Property surname appears in
>@XmlType.propOrder, but no such property exists" error message),
>
@XmlType.propOrder can only contain fields/properties declared within a
class not those
in its super class.

>or if
>I override the methods to simply call super (so as to add them to the
>child class) I get doubling up. Here's my code:
>
you are getting doubling up because class Name is also being mapped since
FullName derives from it. To avoid doubling up, you can mark the fields or
properties (depending upon what you are mapping) with @XmlTransient in
the class Name. For e.g.

public class Name {
        @XmlTransient String givenName;
        @XmlTransient String surname;
        ...
}

regards
Sekhar

>
>@XmlRootElement
>public class Name
>{
> private String givenName;
> private String surname;
>
> public String getGivenName()
> {
> return givenName;
> }
>
> public void setGivenName(String givenName)
> {
> this.givenName = givenName;
> }
>
> public String getSurname()
> {
> return surname;
> }
>
> public void setSurname(String surname)
> {
> this.surname = surname;
> }
>}
>
>@XmlType(propOrder={
> "title",
> "givenName",
> "middleName",
> "surname"
>})
>@XmlRootElement
>public class FullName extends Name
>{
> private String title;
> private String middleName;
>
> public String getTitle()
> {
> return title;
> }
>
> public void setTitle(String title)
> {
> this.title = title;
> }
>
> public String getMiddleName()
> {
> return middleName;
> }
>
> public void setMiddleName(String middleName)
> {
> this.middleName = middleName;
> }
>
> // --------------------------------------------------------------------------------------------
> //
>
> public String getGivenName()
> {
> return super.getGivenName();
> }
>
> public void setGivenName(String givenName)
> {
> super.setGivenName(givenName);
> }
>
> public String getSurname()
> {
> return super.getSurname();
> }
>
> public void setSurname(String surname)
> {
> super.setSurname(surname);
> }
>}
>
>Like I said above, removing the get/set givenName/surname methods from
>FullName I get this:
>
>com.sun.xml.bind.v2.runtime.IllegalAnnotationException: Property
>surname appears in @XmlType.propOrder, but no such property exists
> this problem is related to the following location:
> at com.colebatch.jaxb.order.FullName
>
>and when I include them the output I get is:
>
><?xml version="1.0" encoding="UTF-8" standalone="yes"?>
><fullName>
> <givenName>Dmitri</givenName>
> <surname>Colebatch</surname>
> <title>Mr</title>
> <givenName>Dmitri</givenName>
> <middleName>Feodor</middleName>
> <surname>Colebatch</surname>
></fullName>
>
>Note the doubling up of givenName and surname. I've had a quick look
>at some of the annotations I'm not familiar with (including
>XmlElements which I now think might solve my earlier problem) but
>nothing jumps out at me.
>
>Any thoughts on the above?
>

>
>cheers
>dim
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
>For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>
>