title: How to transform xml into json (and vice versa) if the data contains lists?
body: <p>I'm trying to create a simple xml-json conversor with Jackson (version 2.9.4), but I have a problem with lists.</p>
  <pre><code>package testes;
  
  import com.fasterxml.jackson.databind.JsonNode;
  import com.fasterxml.jackson.databind.ObjectMapper;
  import com.fasterxml.jackson.dataformat.xml.XmlMapper;
  
  public class Main {
      public static void main(String[] args) throws Exception {
          String x = &quot;{\&quot;a\&quot;:[{\&quot;b\&quot;:1,\&quot;c\&quot;:true,\&quot;d\&quot;:\&quot;teste\&quot;},{\&quot;b\&quot;:2,\&quot;c\&quot;:false,\&quot;d\&quot;:\&quot;texto\&quot;}]}&quot;;
          System.err.println(&quot;original: &quot; + x);
          x = jsonToXml(x);
          System.err.println(&quot;xml: &quot; + x);
          x = xmlToJson(x);
          System.err.println(&quot;json: &quot; + x);
      }
  
      private static final ObjectMapper jsonMapper = new ObjectMapper();
      private static final ObjectMapper xmlMapper = new XmlMapper().setDefaultUseWrapper(true);
  
      public static final String jsonToXml(String json) throws Exception {
          final JsonNode node = jsonMapper.readTree(json);
          return xmlMapper.writeValueAsString(node);
      }
  
      public static final String xmlToJson(String xml) throws Exception {
          final JsonNode node = xmlMapper.readTree(xml);
          return jsonMapper.writeValueAsString(node);
      }
  }
  </code></pre>
  <p>Output:</p>
  <pre><code>original: {&quot;a&quot;:[{&quot;b&quot;:1,&quot;c&quot;:true,&quot;d&quot;:&quot;teste&quot;},{&quot;b&quot;:2,&quot;c&quot;:false,&quot;d&quot;:&quot;texto&quot;}]}
  xml: &lt;ObjectNode&gt;&lt;a&gt;&lt;b&gt;1&lt;/b&gt;&lt;c&gt;true&lt;/c&gt;&lt;d&gt;teste&lt;/d&gt;&lt;/a&gt;&lt;a&gt;&lt;b&gt;2&lt;/b&gt;&lt;c&gt;false&lt;/c&gt;&lt;d&gt;texto&lt;/d&gt;&lt;/a&gt;&lt;/ObjectNode&gt;
  json: {&quot;a&quot;:{&quot;b&quot;:&quot;2&quot;,&quot;c&quot;:&quot;false&quot;,&quot;d&quot;:&quot;texto&quot;}}
  </code></pre>
  <p>Is it possible to adjust the settings so that lists are correctly converted between formats?</p>
  <p>I undestand that the property</p>
  <blockquote>
  <p>.setDefaultUseWrapper(true);</p>
  </blockquote>
  <p>should have done the job.</p>