users@jaxb.java.net

No values in JAXBElement wrapped class

From: <eaudet_at_jarics.com>
Date: Wed, 16 Mar 2011 14:11:37 +0000 (GMT)

Hello,

I have generated my java classes using this command:

    xjc -d ./src MySchema.xsd


Everything compiles. Nice!. Here's a part of my xsd in problem:

 ...
 <complexType name="EN">
   <complexContent>
     <extension base="{urn:hl7-org:v3}ANY">
       <sequence>
         <choice maxOccurs="unbounded">
           <element name="delimiter"
type="{urn:hl7-org:v3}en.delimiter"/>
           <element name="family" type="{urn:hl7-org:v3}en.family"/>
           <element name="given" type="{urn:hl7-org:v3}en.given"/>
           <element name="prefix" type="{urn:hl7-org:v3}en.prefix"/>
           <element name="suffix" type="{urn:hl7-org:v3}en.suffix"/>
         </choice>
         <element name="validTime" type="{urn:hl7-org:v3}IVL_TS"
minOccurs="0"/>
       </sequence>
       <attribute name="use" type="{urn:hl7-org:v3}set_EntityNameUse"
/>
     </extension>
   </complexContent>
 </complexType>
 .....



Here's the generated **EN** class:

....
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "EN", propOrder = {
    "content"
})
@XmlSeeAlso({
    ON.class,
    PN.class,
    TN.class
})
public class EN {

    @XmlElementRefs({
        @XmlElementRef(name = "delimiter", namespace =
"urn:hl7-org:v3", type = JAXBElement.class),
        @XmlElementRef(name = "validTime", namespace =
"urn:hl7-org:v3", type = JAXBElement.class),
        @XmlElementRef(name = "suffix", namespace = "urn:hl7-org:v3",
type = JAXBElement.class),
        @XmlElementRef(name = "prefix", namespace = "urn:hl7-org:v3",
type = JAXBElement.class),
        @XmlElementRef(name = "family", namespace = "urn:hl7-org:v3",
type = JAXBElement.class),
        @XmlElementRef(name = "given", namespace = "urn:hl7-org:v3",
type = JAXBElement.class)
    })
    @XmlMixed
    protected List<Serializable> content;
......



Here's the related XML example file in problem (fits with the above
XSD) :



...
                        <person.name>
                                <value>
                                        <family>Smith</family>
                                        <given>John</given>
                                </value>
                        </person.name>
...





Here's the java code doing the unmarshalling in problem:




...
                for (Serializable s :
pPersonName.getValue().getContent()) {
                        if (s instanceof String) {
                                System.out.print((String) s);
                        } else {
                                String tag = ((JAXBElement)
s).getName().getLocalPart();
                                if (s instanceof EnFamily) {
                                        EnFamily chunk = (EnFamily)
((JAXBElement) s).getValue();
                                        System.out.print("(" + tag +
":");
                                }
                        }
                }
...



And here's my problem: The class **EnFamily** extracted from a
JAXBElement does not contain any values. It should contain "Smith". It
seems it is not unmarshalling correctly.

Any help appreciated!

- Erick