简体   繁体   中英

Jackson XML : How to deserialize XML using JacksonXmlElementWrapper with multiple wrapper class

I have a XML String that I need to deserialize

<LOC attribute="example">
   <VehAvail>
      <VehAvailCore>
         <Fees>
             <Fee att1="a" att2="b" att3="c"/>
             <Fee att1="x" att2="y" att3="z"/>
         </Fees>
      </VehAvailCore>
    </VehAvail>
</LOC>

This is what I am trying with but I don't have exact solution for adding the upper two wrappers and

@JacksonXmlElementWrapper(localName = "Fees")
@JacksonXmlProperty(localName="Fee")
private List<Fee> fees = new ArrayList();

How can I deserialize it into Java POJO class with JacksonXML Annotation ?

There can be only one.

Ok, Highlander aside, there can really be only one wrapper around a list of elements.

In your example, you could define just 3 classes: LOC , VehAvailCore , and Fee , and specify wrapper VehAvail around VehAvailCore , and wrapper Fees around Fee .

Of course, it all depends on cardinalities ( minOccurs and maxOccurs ) and what other optional elements/attributes are possible for VehAvail , VehAvailCore , and Fees . Without knowing the full spec, it's impossible to tell.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM