title: Spring Jaxb2RootElementHttpMessageConverter not working with jaxb annotations
body: <p>I have spring set up to use: Jaxb2RootElementHttpMessageConverter as the message converter to convert an object to xml. In my rest service when a response is generated it does not adhere to the JAXB annotations i have provided on the model classes. <br />:</p>
  
  <p>BaseResponse:</p>
  
  <pre><code>@XmlRootElement(name="response")
  @XmlSeeAlso({AddMemberResponse.class,UpdateMemberResponse.class})
  public abstract class BaseResponse {
  
  
      private int status;
      private String message;
      private String confirmationCode;
  
      public String getMessage() {
          return message;
      }
      public void setMessage(String message) {
          this.message = message;
      }
      public int getStatus() {
          return status;
      }
      public void setStatus(int httpInternalError) {
          this.status = httpInternalError;
      }
      public String getConfirmationCode() {
          return confirmationCode;
      }
      public void setConfirmationCode(String confirmationCode) {
          this.confirmationCode = confirmationCode;
      }
  }
  </code></pre>
  
  <p>AddMemberResponse:</p>
  
  <pre><code>@XmlRootElement(name = "response")
  @XmlAccessorType(XmlAccessType.FIELD)
  public class AddMemberResponse extends BaseResponse {
  
      private Member member;
  
      public AddMemberResponse() {
          super();
      }
  
      public Member getMember() {
          return member;
      }
  
      public void setMember(Member member) {
          this.member = member;
      }
  }
  </code></pre>
  
  <p>In one point in my code, I have to save the xml to the database, so I have to manually convert this to a String to be saved later, and for this I use the JaxbMarshaller class and this works fine:</p>
  
  <pre><code>/**
   * Converts object to xml using jaxb marshaller
   */
  private String objectToXML(Object graph) throws IOException {
  
      String finalstring = null;
      try {
  
          Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
          marshaller.setPackagesToScan("com.company.ws");
          Map&lt;String, Object&gt; map = new HashMap&lt;String, Object&gt;();
          map.put("jaxb.formatted.output", true);
          marshaller.setMarshallerProperties(map);
  
          // create a StringWriter for the output
          StringWriter outWriter = new StringWriter();
          StreamResult result = new StreamResult(outWriter);
          marshaller.marshal(graph, result);
  
          StringBuffer sb = outWriter.getBuffer();
          finalstring = sb.toString();
          log.debug(finalstring);
  
      } catch(Exception e) {
          e.printStackTrace();
      }
      return finalstring;
  }
  </code></pre>
  
  <p>It stores this in the database with the jaxbmarshaller like this:</p>
  
  <pre><code>&lt;response&gt;
      &lt;status&gt;500&lt;/status&gt;
  &lt;/response&gt; 
  </code></pre>
  
  <p>But it returns this as the response in POSTMAN:</p>
  
  <pre><code>&lt;AddMemberResponse&gt;
      &lt;status&gt;500&lt;/status&gt;
      &lt;message/&gt;
      &lt;confirmationCode&gt;UVHRWLHB6UMQ&lt;/confirmationCode&gt;
      &lt;member/&gt;
  &lt;/AddMemberResponse&gt;
  </code></pre>
  
  <p>The 500 comes from it not being able to connect to an external service for data, so it is not relevant, it should still return the initial way as described.</p>
  
  <p>app-servlet.xml with the message converters configured:</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context 
          http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"&gt;
  
      &lt;!-- Enables the Spring4 @Controller  --&gt;
      &lt;mvc:annotation-driven /&gt;
  
      &lt;!-- To  convert JSON to Object and vice versa --&gt;
      &lt;bean id="jsonMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"&gt;
      &lt;/bean&gt; 
  
       &lt;!-- To  convert XML to Object and vice versa --&gt;
      &lt;bean id="xmlMessageConverter" class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter"&gt;
      &lt;/bean&gt; 
  
  
  &lt;bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"&gt;
      &lt;property name="messageConverters"&gt;
          &lt;list&gt;
              &lt;ref bean="jsonMessageConverter"/&gt;
              &lt;ref bean="xmlMessageConverter"/&gt;
          &lt;/list&gt;
      &lt;/property&gt; 
  &lt;/bean&gt;     
      &lt;!-- Dozer configuration --&gt;
      &lt;bean id="beanMapper" class="org.dozer.DozerBeanMapper"&gt;
        &lt;property name="mappingFiles"&gt;
          &lt;list&gt;
            &lt;value&gt;dozerMapping.xml&lt;/value&gt;
          &lt;/list&gt;
        &lt;/property&gt;
      &lt;/bean&gt;
  
  
      &lt;context:component-scan base-package="com.company" /&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>Update1:</p>
  
  <pre><code>as "application/xml" using [org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter@3f767117]
  </code></pre>
  
  <p>is showing in the logs, so it isn't using the right converter when marshaling it for the response.</p>