title: Deserializing XML with list using Jackson
body: <p>I have the following XML that I'd like to deserialize to Java POJO.</p>
  
  <pre><code>&lt;testdata&gt;
      &lt;foo&gt;
          &lt;bar&gt;
              &lt;![CDATA[MESSAGE1]]&gt;
          &lt;/bar&gt;
          &lt;bar&gt;
              &lt;![CDATA[MESSAGE2]]&gt;
          &lt;/bar&gt;
          &lt;bar&gt;
              &lt;![CDATA[MESSAGE3]]&gt;
          &lt;/bar&gt;
      &lt;/foo&gt;
  &lt;/testdata&gt;
  </code></pre>
  
  <p>I have the following Java classes</p>
  
  <pre><code>public class TestData {
  
      @JacksonXmlProperty(localName = "foo")
      private Foo foo;
  
      public Foo getFoo() {
          return foo;
      }
  
      public void setFoo(Foo foo) {
          this.foo = foo;
      }
  
  }
  </code></pre>
  
  <p>I have another class like below</p>
  
  <pre><code>public class Foo {
  
      @JacksonXmlProperty(localName = "bar")
      @JacksonXmlCData
      private List&lt;String&gt; barList;
  
      public List&lt;String&gt; getBarList() {
          return barList;
      }
  
      public void setBarList(List&lt;String&gt; barList) {
          this.barList = barList;
      }
  }
  </code></pre>
  
  <p>Now when I run the code using the class below I get an exception</p>
  
  <pre><code>private void readXml() throws FileNotFoundException, IOException {
      File file = new File("/Users/temp.xml");
      XmlMapper xmlMapper = new XmlMapper();
      String xml = GeneralUtils.inputStreamToString(new FileInputStream(file));
      TestData testData = xmlMapper.readValue(xml, TestData.class);
      System.out.println(testData.getFoo()
                                 .getBarList());
  }
  </code></pre>
  
  <p>Exception in thread "main" com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of <code>java.util.ArrayList</code> out of VALUE_STRING token</p>
  
  <p>How do I convert <code>bar</code> elements into a <code>List</code>? I tried multiple things but I keep getting some or the other errors</p>