0

I need to deserialize XML in the following format:

<foo>
    <field1>
        <value>ABC</value>
        <text>A B C</text>
    </field1>
    <field2>
        <value>DEF</value>
        <text>D E F</text>
    </field2>
    <field3>1234</field3>
</foo>

Note that field1 and field2 are different types that implement a common interface. This class does not represent a list.

I don't actually care about the <value> elements, and so want to simply ignore them and use the value of the <text> elements as the fields value. The intention is to then deserialize the above XML into a type that looks like:

public class FooSimple {
    private String field1;    // holds value of field1.text element
    private String field2;    // holds value of field2.text element
    private int field3;

    // constructor and getters
}

How can this be done? I want to avoid changing FooSimple to include fields that directly map to the XML.

Daniel Kelley
  • 7,579
  • 6
  • 42
  • 50
  • You can check a similar question https://stackoverflow.com/questions/13731322/xml-parsing-and-deserialization if it helps – Ravi Chandra May 30 '17 at 09:52
  • Unfortunately that question relates to lists. In my scenario `field1` and `field2` represent different types (that implement a common interface which exposes `value` and `text` properties). – Daniel Kelley May 30 '17 at 09:55

0 Answers0