title: Customize Jackson XML response in Spring REST
body: <p>At the moment I have a Spring REST service which is able to generate JSON and XML but the XML response in not exactly what I'm looking for.</p>
  
  <p>This is what I've build so far is:</p>
  
  <p>The XSD object</p>
  
  <pre><code>&lt;xs:element name="project"&gt;
      &lt;xs:complexType&gt;
          &lt;xs:complexContent&gt;
              &lt;xs:extension base="projectBase"/&gt;
          &lt;/xs:complexContent&gt;
      &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
  
  &lt;xs:complexType name="projectBase"&gt;
      &lt;xs:attribute type="xs:string" name="name" use="required" /&gt;
      &lt;xs:attribute type="xs:string" name="id" use="optional" /&gt;
      &lt;xs:attribute type="xs:anyURI" name="self" use="optional" /&gt;
  &lt;/xs:complexType&gt;
  </code></pre>
  
  <p>The POM</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
      &lt;artifactId&gt;jackson-core&lt;/artifactId&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;com.fasterxml.jackson.dataformat&lt;/groupId&gt;
      &lt;artifactId&gt;jackson-dataformat-xml&lt;/artifactId&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
      &lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;
  &lt;/dependency&gt;
  &lt;dependency&gt;
      &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
      &lt;artifactId&gt;jackson-annotations&lt;/artifactId&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>The Controller</p>
  
  <pre><code>@ApiOperation(value = "GET",
          notes = "Returns a list of exisiting projects.")
  @RequestMapping(method = RequestMethod.GET, produces = {"application/smartask.projectsV1+xml", "application/smartask.projectsV1+json"})
  public List&lt;be.smartask.api.model.smartask.Project&gt; getProjects(@ApiParam(value = "page of found projects", required = false) @RequestParam(value = "page", required = false, defaultValue = "0") int page,
                                                                  @ApiParam(value = "size(min:5, max:50) of projects on a page", required = false) @RequestParam(value = "size", required = false, defaultValue = "10") int size) throws ServiceException, ConversionException {
      String uri = getURLWithContextPath(this.request);
      List&lt;be.smartask.api.model.smartask.Project&gt; projects = projectConverter.convertToObjectList(projectService.findAll(page, size), uri);
      return projects;
  }
  </code></pre>
  
  <p>The result I get when I execute this getProjects method is</p>
  
  <pre><code>&lt;List xmlns=""&gt;
    &lt;item&gt;
      &lt;name&gt;project1&lt;/name&gt;
      &lt;id&gt;7a666889-9b03-4790-8100-d41a9de66a63&lt;/id&gt;
      &lt;self&gt;http://localhost/ask/projects/7a666889-9b03-4790-8100-d41a9de66a63&lt;/self&gt;
    &lt;/item&gt;
    &lt;item&gt;
      &lt;name&gt;project2&lt;/name&gt;
      &lt;id&gt;f784ede1-d019-46e9-b7a4-83c51d6f7d8e&lt;/id&gt;
      &lt;self&gt;http://localhost/ask/projects/f784ede1-d019-46e9-b7a4-83c51d6f7d8e&lt;/self&gt;
    &lt;/item&gt;
    &lt;item&gt;
      &lt;name&gt;project3&lt;/name&gt;
      &lt;id&gt;936e3ed9-b8c6-46ab-9570-60dcfcaaa670&lt;/id&gt;
      &lt;self&gt;http://localhost/ask/projects/936e3ed9-b8c6-46ab-9570-60dcfcaaa670&lt;/self&gt;
    &lt;/item&gt;
    &lt;item&gt;
      &lt;name&gt;project4&lt;/name&gt;
      &lt;id&gt;4eaa6045-bbc4-423d-8bae-1da11692114b&lt;/id&gt;
      &lt;self&gt;http://localhost/ask/projects/4eaa6045-bbc4-423d-8bae-1da11692114b&lt;/self&gt;
    &lt;/item&gt;
  &lt;/List&gt;
  </code></pre>
  
  <p>Which is already pretty close, but I would like to replace the List and Item tags with Projects and Project.</p>
  
  <p>So far I've tried to add various annotations like</p>
  
  <ul>
  <li>@JacksonXmlElementWrapper(useWrapping = false)</li>
  <li>@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT)</li>
  <li>@JacksonXmlElementWrapper(useWrapping = true, localName = "projects")</li>
  <li>@JacksonXmlProperty(localName = "project")</li>
  <li>@JacksonXmlRootElement(localName = "project")</li>
  </ul>
  
  <p>The first 4 I used on my controller method and the last one I used on the generated object (both Project and ProjectBase), but nothing happens. </p>
  
  <p>What am I doing wrong or what have I forgotten to accomplish this?</p>
  
  <p>I would like to keep my JSON output as it is though</p>
  
  <pre><code>[
    {
      "name": "project1",
      "id": "7a666889-9b03-4790-8100-d41a9de66a63",
      "self": "http://localhost/ask/projects/7a666889-9b03-4790-8100-d41a9de66a63"
    }
  ]
  </code></pre>
  
  <p>and not</p>
  
  <pre><code>{
      "Projects": {
          "Project": [{
              "name": "project1",
              "id": "7a666889-9b03-4790-8100-d41a9de66a63",
              "self": "http://localhost/ask/projects/7a666889-9b03-4790-8100-d41a9de66a63"
          }]
      }
  }
  </code></pre>
  
  <p>Edit #1</p>
  
  <p>Someone suggested me to take a look at this guide:</p>
  
  <p><a href="https://pascaldimassimo.com/2010/04/13/how-to-return-a-single-json-list-out-of-mappingjacksonjsonview/" rel="nofollow">https://pascaldimassimo.com/2010/04/13/how-to-return-a-single-json-list-out-of-mappingjacksonjsonview/</a> </p>
  
  <p>but haven't succeeded in making this work.</p>