title: Jackson XML - deserializing XML with namespace prefixes
body: <p>I'm working with the Jackson XML plugin (<a href="https://github.com/FasterXML/jackson-dataformat-xml" rel="noreferrer">https://github.com/FasterXML/jackson-dataformat-xml</a>), and I'm not sure if it's supported, but I'm wondering if it's possible to both serialize and deserialize XML with namespace prefixes, like so:</p>
  
  <pre><code>&lt;name:Foo&gt;
    &lt;name:Bar&gt;
      &lt;name:x&gt;x&lt;/name:x&gt;
      &lt;name:y&gt;y&lt;/name:y&gt;
    &lt;/name:Bar&gt;
  &lt;/name:Foo&gt;
  </code></pre>
  
  <p>I can generate this type of XML using Jackson's plugin like so:</p>
  
  <pre><code>@JacksonXmlProperty(localName="name:Bar")
  public Bar getBar() {
      return bar;
  }
  </code></pre>
  
  <p>However, I can't find a way to configure my POJOs to deserialize from the XML generated. Please see the following example code:</p>
  
  <pre><code>public class Bar{
      @JacksonXmlProperty(localName="name:x")
      public String x = "x";
      @JacksonXmlProperty(localName="name:y")
      public String y = "y";
  }
  </code></pre>
  
  <hr>
  
  <pre><code>@JacksonXmlRootElement(localName="name:Foo")
      public class Foo{
          private Bar bar;
  
          @JacksonXmlProperty(localName="name:Bar")
          public Bar getBar() {
             return bar;
          }
  
          public void setBar(Bar bar) {
              this.bar = bar;
          }   
  }
  </code></pre>
  
  <hr>
  
  <pre><code>public class TestDeserialization {
  
      public static void main(String[] args) throws Exception {
          Foo foo = new Foo();
          foo.setBar(new Bar());
  
          XmlMapper xmlMapper = new XmlMapper();
          String xml = xmlMapper.writerWithDefaultPrettyPrinter().writeValueAsString(foo);
          System.out.println(xml);
          System.out.println("XML Desearialzing....");
          Foo foo2= xmlMapper.readValue(xml, Foo.class);
          System.out.println(xmlMapper.writeValueAsString(foo2));
       }
  }
  </code></pre>
  
  <p>Trying to run this test gives me an exception: </p>
  
  <pre><code>Exception in thread "main" java.io.IOException: com.ctc.wstx.exc.WstxParsingException: Undeclared namespace prefix "name"
  </code></pre>
  
  <p>which is understandable, but I was wondering if there's a way to get this to work with Jackson XML?</p>