users@jaxb.java.net

Re: Problems generating objects from complexContent

From: Bastien Jansen <bjansen_at_excilys.com>
Date: Thu, 11 Aug 2011 12:35:56 +0200

Yes but the problem is that in the content I only get the PartyName. For
example if I unmarshall the following extract:

<DisplayArtist>
<PartyName>
<FullName>Mary Mary</FullName>
</PartyName>
<ArtistRole>MainArtist</ArtistRole>
</DisplayArtist>

In the DisplayArtist's content, I only have 1 element PartyName with value
"Mary Mary", but no ArtistRole.
I don't know how JAXB works internally, but in PartyDescriptor, there is no
@XmlElementRef for ArtistRole, can this be the cause of why it's not mapped?

public class PartyDescriptor {

    @XmlElementRefs({
        @XmlElementRef(name = "PartyId", type = JAXBElement.class),
        @XmlElementRef(name = "PartyName", type = JAXBElement.class)
    })
    protected List<JAXBElement<?>> content;

    ...

On 11 August 2011 12:19, Wolfgang Laun <wolfgang.laun_at_gmail.com> wrote:

> The base class PartyDescriptor has "naughty children" so that its content
> all has to go into a catch-all List<JAXBElement>.
>
> See the javadoc in PartyDescriptor for a description of what is bad and for
> a tip of how to fix it.
>
> -W
>
>
>
> On 10 August 2011 23:35, Bastien Jansen <bjansen_at_excilys.com> wrote:
>
>> Hi,
>>
>> I'm trying to generate Java objects from the DDEX XSD (
>> http://ddex.net/xml/20081015/ddexC.xsd) using JAXB. The problem is that
>> the generated objects are missing java attributes.
>> For example, this element definition:
>>
>> <xs:complexType name="DisplayArtist">
>> <xs:complexContent>
>> <xs:extension base="ddexC:PartyDescriptor">
>> <xs:sequence>
>> <xs:element name="ArtistRole" type="ddexC:ArtistRole"
>> minOccurs="0"
>> maxOccurs="unbounded">
>> </xs:element>
>> </xs:sequence>
>> <xs:attribute name="SequenceNumber" type="xs:integer"
>> use="optional">
>> </xs:attribute>
>> </xs:extension>
>> </xs:complexContent>
>> </xs:complexType>
>>
>> is translated into
>>
>> @XmlAccessorType(XmlAccessType.FIELD)
>> @XmlType(name = "DisplayArtist")
>> public class DisplayArtist
>> extends PartyDescriptor
>> {
>>
>> @XmlAttribute(name = "SequenceNumber")
>> protected BigInteger sequenceNumber;
>>
>> public BigInteger getSequenceNumber() {
>> return sequenceNumber;
>> }
>>
>> public void setSequenceNumber(BigInteger value) {
>> this.sequenceNumber = value;
>> }
>>
>> }
>>
>> DisplayArtist.java is missing a List<ArtistRole>. I don't know why it is
>> not generated. I noticed that if if remove the complexContent and extension
>> tags, I get what I want (but I loose the inheritance...).
>>
>> Does anyone know why this happens?
>>
>
>