title: How to use Jackson's JaxbAnnotationIntrospector correctly?
body: <p>I'm able to generate the XML I want using @JacksonXmlProperty annotations with the default mapper configuration. But my classes are generated by maven-jaxb2-plugin and already have the @XmlAttribute annotations. When I try using the JaxbAnnotationIntrospector it serializes the attributes as child elements. What am I doing wrong?</p>
  
  <p>Expected output: <code>&lt;problem xmlns="" id="aaa"&gt;&lt;description&gt;test&lt;/description&gt;&lt;/problem&gt;</code> (repeatable with testGenerateXmlCorrect)</p>
  
  <p>Actual output: <code>&lt;problem xmlns=""&gt;&lt;id&gt;aaa&lt;/id&gt;&lt;description&gt;test&lt;/description&gt;&lt;/problem&gt;</code> (repeatable with testGenerateXmlWrong)</p>
  
  <p>I can also generate the expected XML using JAXB but this question is how to do it with Jackson using the JaxbAnnotationIntrospector.</p>
  
  <p>Junit test:</p>
  
  <pre><code>import com.fasterxml.jackson.core.JsonProcessingException;
  import com.fasterxml.jackson.dataformat.xml.XmlMapper;
  import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
  import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
  import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector;
  import javax.xml.bind.annotation.XmlAttribute;
  import javax.xml.bind.annotation.XmlRootElement;
  import org.junit.Test;
  
  public class JaxbAttributeTest {
  private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(JaxbAttributeTest.class);
  
  @XmlRootElement(name="problem")
  public static class ProblemJaxb {
      @XmlAttribute(name="id")     
      public String id;
      public String description;
  }
  
  @Test
  public void testGenerateXmlWrong() throws JsonProcessingException {
      ProblemJaxb problem = new ProblemJaxb();
      problem.id = "aaa";
      problem.description = "test";
      XmlMapper xmlMapper = new XmlMapper();
      xmlMapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(xmlMapper.getTypeFactory()));
      log.debug("ProblemJaxb: {}", xmlMapper.writeValueAsString(problem)); 
  }
  
  @JacksonXmlRootElement(localName="problem")
  public static class ProblemJackson {
      @JacksonXmlProperty(isAttribute=true)
      public String id;
      public String description;
  }
  
  @Test
  public void testGenerateXmlCorrect() throws JsonProcessingException {
      ProblemJackson problem = new ProblemJackson();
      problem.id = "aaa";
      problem.description = "test";
      XmlMapper xmlMapper = new XmlMapper();
      log.debug("ProblemJackson: {}", xmlMapper.writeValueAsString(problem));
  }
  
  }
  </code></pre>
  
  <p>Classpath includes:</p>
  
  <ul>
  <li>com.fasterxml.jackson.core:jackson-core:jar:2.3.2</li>
  <li>com.fasterxml.jackson.core:jackson-annotations:jar:2.3.2</li>
  <li>com.fasterxml.jackson.core:jackson-databind:jar:2.3.2</li>
  <li>com.fasterxml.jackson.dataformat:jackson-dataformat-xml:jar:2.3.2</li>
  <li>com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.3.2</li>
  <li>org.codehaus.woodstox:stax2-api:jar:3.1.1</li>
  <li>javax.xml.stream:stax-api:jar:1.0-2</li>
  <li>com.sun.xml.bind:jaxb-impl:jar:2.2.7</li>
  <li>com.sun.xml.bind:jaxb-core:jar:2.2.7</li>
  <li>javax.xml.bind:jaxb-api:jar:2.2.7</li>
  </ul>
  
  <p>By the way I also tried configuring the XmlMapper with this:</p>
  
  <pre><code>xmlMapper.getSerializationConfig().with(new JaxbAnnotationIntrospector(xmlMapper.getTypeFactory()));
  </code></pre>
  
  <p>but that generated even worse output because the root element name was incorrect: <code>&lt;ProblemJaxb xmlns=""&gt;&lt;id&gt;aaa&lt;/id&gt;&lt;description&gt;test&lt;/description&gt;&lt;/ProblemJaxb&gt;</code></p>