title: Spring boot REST API Returning a List/Array Formatting issue
body: <p>I am developing spring boot based web services API. I need to return a list of things (ProductData) for the GET response. </p>
  
  <p>This is what the response looks like</p>
  
  <pre><code>&lt;ProductDataList&gt;
    &lt;ProductData&gt;
       &lt;ProductData&gt;...&lt;/ProductData&gt;
       &lt;ProductData&gt;...&lt;/ProductData&gt;
       &lt;ProductData&gt;...&lt;/ProductData&gt;
    &lt;/ProductData&gt;
  &lt;/ProductDataList&gt;
  </code></pre>
  
  <p>But I don't need the extra <code>&lt;ProductData&gt;</code> tag.
  I need the response as below.</p>
  
  <pre><code>  &lt;ProductDataList&gt;
      &lt;ProductData&gt;...&lt;/ProductData&gt;
      &lt;ProductData&gt;...&lt;/ProductData&gt;
      &lt;ProductData&gt;...&lt;/ProductData&gt;
    &lt;/ProductDataList&gt;
  </code></pre>
  
  <p>Any idea why an extra tag is generated? </p>
  
  <p>I have below in my WebMvcConfig file.</p>
  
  <pre><code>  @Bean
  public MappingJackson2XmlHttpMessageConverter xmlConverter() {
      Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
      builder.propertyNamingStrategy(PropertyNamingStrategy.
              PascalCaseStrategy.PASCAL_CASE_TO_CAMEL_CASE);
      builder.serializationInclusion(JsonInclude.Include.NON_EMPTY);
      builder.failOnUnknownProperties(false);
      MappingJackson2XmlHttpMessageConverter xmlConverter =
              new MappingJackson2XmlHttpMessageConverter(builder.createXmlMapper(true).build());
      return xmlConverter;
  }
  </code></pre>
  
  <p>In my controller I have </p>
  
  <pre><code>@RequestMapping(value = "/productdata")
  @ResponseBody
  public ProductDataList getProductData(@RequestParam final String[] ids) {        
      ArrayList&lt;ProductData&gt; products = productDataService.getProductData(ids);
  
      ProductData[] pdArray = new ProductData[products.size()];
      products.toArray(pdArray);
      ProductDataList productDataList = new ProductDataList();
      productDataList.setProductData(pdArray);
  
      return productDataList;
  }
  </code></pre>
  
  <p>This is my ProductDataList class.</p>
  
  <pre><code>public class ProductDataList{
  
       ProductData[] productData;
  
       public ProductData[] getProductData() {
             return productData;
       }
  
       public void setProductData(ProductData[] productData) {
             this.productData = productData;
       }
  }
  </code></pre>
  
  <hr>
  
  <p><strong>Edit 1.</strong> </p>
  
  <p>When I return <code>ArrayList&lt;ProductData&gt;</code> the response was like this.</p>
  
  <pre><code>&lt;ArrayList&gt;
    &lt;item&gt;...&lt;/item&gt;
    &lt;item&gt;...&lt;/item&gt;
    &lt;item&gt;...&lt;/item&gt;
  &lt;/ArrayList&gt;
  </code></pre>
  
  <p><strong>Edit 2.</strong> 
  After adding annotation <code>JsonTypeInfo</code> I made some progress, but not quite there to what I wanted.</p>
  
  <pre><code>@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY)
  public class ProductData {}
  
  &lt;ProductDataList&gt;
       &lt;item _type="ProductData"&gt;...&lt;/item&gt;
       &lt;item _type="ProductData"&gt;...&lt;/item&gt;
       &lt;item _type="ProductData"&gt;...&lt;/item&gt;
  &lt;ProductDataList&gt;
  </code></pre>