Search code examples
javaxmlxml-deserialization

Deserialization of xml with attribute AND value


i have little bit trouble with deserialization of XML. I am only able to deserialize this xml by:

@JacksonXmlProperty(localName = "field")
@JacksonXmlElementWrapper(useWrapping = false)
List<Object> field;

This is my xml:

   <Response>
       <user>
          <field attribute="x"></field>
          <field attribute="y">false</field>
          <field attribute="z">string</field>
       </user>
       <user>
          <field attribute="x"></field>
          <field attribute="y">false</field>
          <field attribute="z">string</field>
       </user>
   </Response>

Problem is, that i want to replace Object in List<Object> field; with some specific class so i could access attribute and the value in field.

With Object, i am able to create something like this:

user='[{attribute=x}, {attribute=y, =false}, {name=z, =string}]

thanks a lot.


Solution

  • Found answer. I created new class that contains this elements:

            @JacksonXmlProperty(isAttribute = true, localName = "attribute")
            String attribute;
    
            @JacksonXmlText
            String value;
    

    And replace the Object with this new class.