dardo
dardo

Reputation: 4970

Bind XSD element to List of items

Is there a way to directly bind a list of elements to the wrapper element. Note, I am currently generating these classes from the XSD.

What I mean is this:

<wrapperElement>
  <listItem />
  ...
  <listItem />
</wrapperElement>

Currently, this would unmarshal to the following objects:

SomeJaxbObject
  +WrapperElement

WrapperElement
  +List<ListItem> listItem

Is there a way to directly bind that wrapper element as a list of objects as follows:

SomeJaxbObject
  +List<ListItem> listItems

I'm guessing this would require some custom bindings through an xjb file.

Thanks a bunch!

Upvotes: 2

Views: 250

Answers (1)

bdoughan
bdoughan

Reputation: 149027

You could do the following:

@XmlElementWrapper(name="wrapperElement")
@XmlElement(name="listItem")
public List<ListItem> getListItems() {
    return listItems;
}

Upvotes: 1

Related Questions