title: List serialization to XML in Spring
body: <p>I want to serialize in my controller List of Country objects to XML in Spring, but I receive data in incorrect format, like this:</p>
  <pre><code>&lt;List&gt;
     &lt;item&gt;
        &lt;country&gt;&lt;id&gt;1&lt;/id&gt;&lt;iso&gt;AF&lt;/iso&gt;&lt;namePl&gt;Afganistan&lt;/namePl&gt;&lt;citizenshipPl&gt;Afganistanu&lt;/citizenshipPl&gt;&lt;nameEn&gt;AFGHANISTAN&lt;/nameEn&gt;&lt;citizenshipEn&gt;of Afghanistan&lt;/citizenshipEn&gt;&lt;/country&gt;
     &lt;/item&gt;
     &lt;item&gt;
        &lt;country&gt;&lt;id&gt;2&lt;/id&gt;&lt;iso&gt;AL&lt;/iso&gt;&lt;namePl&gt;Albania&lt;/namePl&gt;&lt;citizenshipPl&gt;Albanii&lt;/citizenshipPl&gt;&lt;nameEn&gt;ALBANIA&lt;/nameEn&gt;&lt;citizenshipEn&gt;of Albania&lt;/citizenshipEn&gt;&lt;/country&gt;
     &lt;/item&gt;
  &lt;/List&gt;
  </code></pre>
  <p>and I want to get following format:</p>
  <pre><code>&lt;countries&gt;
     &lt;country&gt;
        &lt;id&gt;1&lt;/id&gt;&lt;iso&gt;AF&lt;/is&gt;o&lt;namePl&gt;Afganistan&lt;/namePl&gt;&lt;citizenshipPl&gt;Afganistanu&lt;/citizenshipPl&gt;&lt;nameEn&gt;AFGHANISTAN&lt;/nameEn&gt;&lt;citizenshipEn&gt;of Afghanistan&lt;/citizenshipEn&gt;
     &lt;/country&gt;
     &lt;country&gt;
        &lt;id&gt;2&lt;/id&gt;&lt;iso&gt;AL&lt;/iso&gt;&lt;namePl&gt;Albania&lt;/namePl&gt;&lt;citizenshipPl&gt;Albanii&lt;/citizenshipPl&gt;&lt;nameEn&gt;ALBANIA&lt;/nameEn&gt;&lt;citizenshipEn&gt;of Albania&lt;/citizenshipEn&gt;
     &lt;/country&gt;
  &lt;/countries&gt;
  </code></pre>
  <p>do You know what am I doing wrong? How to set name of xml nodes as I want? Where I should put node names values?</p>
  <p>My classes:</p>
  <p>CountryVO:</p>
  <pre><code>@Data
  @AllArgsConstructor
  
  @XmlRootElement(name = &quot;country&quot;)
  @JacksonXmlRootElement(localName = &quot;country&quot;)
  public class CountryVO implements Serializable {
  
      @XmlAttribute
      private Long id;
  
      @XmlAttribute
      private String iso;
  
      @XmlAttribute
      private String namePl;
  
      @XmlAttribute
      private String citizenshipPl;
  
      @XmlAttribute
      private String nameEn;
  
      @XmlAttribute
      private String citizenshipEn;
  }
  </code></pre>
  <p>CountriesVO:</p>
  <pre><code>@Data
  @AllArgsConstructor
  
  public class CountriesVO implements Serializable {
  
      @JacksonXmlProperty(localName = &quot;country&quot;)
      private List&lt;CountryVO&gt; countries;
  }
  </code></pre>
  <p>Controller:</p>
  <pre><code>@Controller
  @RequestMapping(&quot;/api/country&quot;)
  public class CountryWebService {
  
      @Autowired
      private CountryService countryService;
  
      @Autowired
      private ResourceBundleService resourceBundleService;
  
      @RequestMapping(value = &quot;/country&quot;, method = RequestMethod.GET, produces = &quot;text/xml;charset=UTF-8&quot;)
      public @ResponseBody String getCountries() throws JsonProcessingException {
          XmlMapper xmlMapper = new XmlMapper();
          List&lt;Country&gt; countries = countryService.getAll();
          List&lt;CountryVO&gt; output = new ArrayList();
          String citizenshipEn,citizenshipPl, xmlString;
  
          for (Country country : countries) {
              citizenshipEn=resourceBundleService.getStringValue(ResourceBundleService.ResourceBundle.NATIONALITIES,ResourceBundleService.LANG_EN,country.getIso());
              citizenshipPl=resourceBundleService.getStringValue(ResourceBundleService.ResourceBundle.NATIONALITIES,ResourceBundleService.LANG_PL,country.getIso());
              output.add(new CountryVO(country.getId(),country.getIso(),country.getNamePl(),citizenshipPl,country.getName(),citizenshipEn));
          }
  
          return xmlMapper.writeValueAsString(output);
  
      }
  }
  </code></pre>