dev@jaxb.java.net

Re: JAXB: Unmarshalling does not always populate certain classes?

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Mon, 22 Feb 2010 23:27:33 +0100

Hi,

please use the users_at_jaxb.dev.java.net for support requests.

> ...now this will generate JAXBElement types due the the "choice" with a
> "maxOccurs > 1" . I want to avoid those, so I did that by modifying the code
> to use a "Wrapper" element and move the maxOccurs up to a sequence tag as
> follows...
>
>
> Code:
> <xs:complexType name="IDType">
> <xs:sequence maxOccurs="2">
>  <xs:element name=Wrapper>
>  <xs:complexType>
>  <xs:choice>
>  <xs:element name="DriversLicense"    minOccurs="0" maxOccurs="1"
> type="an..35" />
>    <xs:element name="SSN"        minOccurs="0" maxOccurs="1" type="an..35"
> />
>    <xs:element name="CompanyID"       minOccurs="0" maxOccurs="1"
> type="an..35" />
>  </xs:choice>
>  </xs:complexType>
>  </xs:element>
> </xs:sequence>
> </xs:complexType>
>
> <xs:simpleType name="an..35">
>  <xs:restriction base="an">
>    <xs:maxLength value="35" />
>  </xs:restriction>
> </xs:simpleType>
>
> <xs:simpleType name="an">
>   <xs:restriction base="xs:string">
>     <xs:pattern value="[ !-~]*" />
>   </xs:restriction>
> </xs:simpleType>
>
> For class generating, looks like it works great - the JAXB element is
> replaced with a list of wrappers as String (i.e. List<IDType.Wrapper<String>
> ) and compiles fine.
>
> However, when I unmarshall the actual XML data into the generated classes
> the data in the wrapper class is not populated - yet JAXB does not throw an
> exception.

Have you updated your XML to include the Wrapper element?

Bye.
/lexi