title: How to translate Java list into XML using JAXB annotations?
body: <p>How can I translate Java list</p>
  
  <pre><code>List&lt;String&gt; locations
  </code></pre>
  
  <p>into XML representation</p>
  
  <pre><code>...
  
  &lt;locations&gt;
      &lt;location&gt;/bob/app/l1.xml&lt;/location&gt;
      &lt;location&gt;/bob/app/l2.xml&lt;/location&gt;
      &lt;location&gt;/bob/app/l3.xml&lt;/location&gt;
  &lt;/locations&gt;
  
  ...
  </code></pre>
  
  <p>and save JSON compatibility format at the same time:</p>
  
  <pre><code>...
  
  "locations": ["/bob/app/l1.xml","/bob/app/l2.xml"]
  
  ...    
  </code></pre>
  
  <p>I use Spring and my current XML format in which I get responses is</p>
  
  <pre><code>...
  &lt;locations&gt;/bob/app/l1.xml&lt;/locations&gt;
  &lt;locations&gt;/bob/app/l2.xml&lt;/locations&gt;
  ...
  </code></pre>
  
  <p>I use JAXB annotations</p>
  
  <pre><code>@XmlElement(name = "locations")
  public void setLocations(List&lt;String&gt; locations) {
      this.locations = locations;
  }
  </code></pre>
  
  <p><em>UPD</em></p>
  
  <p>I've found a solution. I just need to use </p>
  
  <pre><code>@XmlElementWrapper(name = "locations")
  @XmlElement(name = "location")
  public List&lt;String&gt; getLocations() {
      return locations;
  }
  </code></pre>