users@jaxb.java.net

Re: Problems generating objects from complexContent

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Thu, 11 Aug 2011 17:08:40 +0200

As I wrote: it may well be a bug, but at least it's a borderline case ;-)
-W

On 11 August 2011 13:40, Bastien Jansen <bjansen_at_excilys.com> wrote:

> Thanks for your help, I should have read your first answer twice to look
> carefully at the javadoc :)
> So I renamed one of the two "PartyId" attribute in my Java class and
> everything is working as expected. I got rid of the content attribute, and
> I have an artistRole in DisplayArtist.
>
> So if I understand correctly, when there is such element "conflict" in the
> parent class, it's not possible for the child class to add new values in
> the List<JAXBElement<?>> because it's not possible to add new annotations
> to the child?
>
>
> On 11 August 2011 13:03, Wolfgang Laun <wolfgang.laun_at_gmail.com> wrote:
>
>> The @XmlElementRef can't be there because then the parent class would not
>> be correct.
>>
>> But as <ArtistRole> seems to be clean, one should think that it is
>> possible to map this element separately and correctly in the first place;
>> all of these follow the mishmash from the parent <DisplayArtist>.
>>
>> But working with Lists of JAXBElements isn't nice anyway - is following
>> the javadoc's advice not possible for you?
>>
>> -W
>>
>>
>> On 11 August 2011 12:35, Bastien Jansen <bjansen_at_excilys.com> wrote:
>>
>>> 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?
>>>>>
>>>>
>>>>
>>>
>>
>