2

I have XML file where the last line is a commented text and contains unique ID XXX. The goal is a deserialize the comment value of a property.

<countries>
  <code>AD<code/>
  <code>AE<code/>     
</countries>
<!-- RUID: [XXXX] -->

Expected class structure

@JacksonXmlRootElement(localName = "countries")
public class CountriesRS {
    String RUID; // the property to store velue from  <!-- RUID: [XXXX] -->
    List<String> code;
}

Code to read value

XmlMapper xmlMapper = new XmlMapper();

CountriesRS rs = xmlMapper.readValue(detailsString, CountriesRS.class);

How can I configure XmlMapper to do this?

I have use jackson-dataformat-xml version 2.8

Tioma
  • 2,120
  • 9
  • 35
  • 52
  • 2
    I am not an expect on xml deserialization with jackson, but I am pretty sure you'll need to hack it yourself. Take the file or the input that you get, parse the comments and build your rest of the xml with the `XmlMapper`, and set at the end the what parsing you did in your CountriesRS object – Andrei Sfat Nov 16 '17 at 17:08
  • If you have any helpful examples how to customize XmlMapper, please share with me. – Tioma Nov 17 '17 at 13:01

0 Answers0