问题
I have two different XML structures I'd like to map to one domain object. I'm using MOXy's external binding support so I can choose which binding to use dynamically.
Here's my question. I have an XML structure like the one below:
<entity>
<compoundID_one>foo</compoundID_one>
<compoundID_two>bar</compoundID_two>
</entity>
I'd like to have a single List<String>
field in my domain class which would contain 'foo' and 'bar'
I've tried this:
...
<java-attributes>
<xml-elements>
<xml-element java-attribute="idList" name="compoundID_one" />
<xml-element java-attribute="idList" name="compoundID_two" />
</xml-elements>
</java-attributes>
...
but I just get null
for the field in the domain object. If I omit the xml-elements
wrapper I only get one of the compoundID's in the list.
I found this question which seems to suggest this should work. Am I doing something wrong or is there a better way to do this?
回答1:
I just had the binding XML wrong, it should be:
...
<java-attributes>
<xml-elements java-attribute="idList">
<xml-element name="compoundID_one" />
<xml-element name="compoundID_two" />
</xml-elements>
</java-attributes>
...
All works fine now.
来源:https://stackoverflow.com/questions/15917610/is-it-possible-with-jaxb-to-marshal-two-or-more-elements-into-one-domain-object