2

I have a piece of XSD reads as below

<xs:schema ...>
    <xs:element name="order" type="tns:order/>
    <xs:complexType name="order">
        <xs:sequence>
            <xs:element .../>
            <xs:element name="itemList" minOccurs="0">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="item" type="tns:item" minOccurs="0" maxOccurs="unbounded"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="item">
        <xs:sequence>
            ...
        </xs:sequence>
    </xs:complexType>
</xs:schema>

By default, an Order class is generated with a nested class Order.ItemList. The signature of the itemList field within Order class is:

protected Order.ItemList itemList;

However I am expecting the type of itemList is java.util.List, i.e.

protected List<Item> itemList;

How can I achieve this through the external binding file? I am aware of this link but the accepted answer doesn't work for me as I have no control over this schema (it is part of a WSDL)

Community
  • 1
  • 1
Hong
  • 55
  • 5
  • try moving the type definition for itemList outside of the type definition for order. – tdrury Feb 01 '14 at 21:06
  • @tdrury: As I mentioned in my post, I have no control over the schema, it's part of my client web service description. – Hong Feb 02 '14 at 22:30

1 Answers1

1

You must annotate your List itemList with @XmlElementWrapper. You can do it in two ways:

  • Manually (not an option if you are autogenerating the classes from the schema, i.e. using xjc)
  • With the jaxb-xew-plugin plugin.

    The plugin is used together with the xjc from the command line or from an Ant task or via maven-jaxb2-plugin.

Related answers:

Community
  • 1
  • 1
gabrielgiussi
  • 9,245
  • 7
  • 41
  • 71
  • XEW plugin is useful to prevent wrapper classes specially, List classes. I had a similar requirement and struggled and tried to blog about it at [YoursAndMyIdeas - Data contracts, XEW And Redundant List Wrappers](https://yoursandmyideas.com/2017/07/20/data-contracts-xsds-and-redundant-list-wrappers-xew-plugin-to-rescue/). – Sunil Singhal Sep 07 '17 at 07:11