title: Define Spring JAXB namespaces without using NamespacePrefixMapper
body: <p>[Heavily edited as understanding progresses]</p>
  
  <p>Is it possible to get Spring Jaxb2Marshaller to use a custom set of namespace prefixes (or at least respect the ones given in the schema file/annotations) without having to use an extension of a NamespacePrefixMapper?</p>
  
  <p>The idea is to have a class with a "has a" relationship to another class that in turn contains a property with a different namespace. To better illustrate this consider the following project outline which uses JDK1.6.0_12 (the latest I can get my hands on at work). I have the following in the package org.example.domain:</p>
  
  <p>Main.java:</p>
  
  <pre><code>package org.example.domain;
  
  import javax.xml.bind.JAXBContext;
  import javax.xml.bind.JAXBException;
  import javax.xml.bind.Marshaller;
  
  public class Main {
    public static void main(String[] args) throws JAXBException {
      JAXBContext jc = JAXBContext.newInstance(RootElement.class);
  
      RootElement re = new RootElement();
      re.childElementWithXlink = new ChildElementWithXlink();
  
      Marshaller marshaller = jc.createMarshaller();
      marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
      marshaller.marshal(re, System.out);
    }
  
  }
  </code></pre>
  
  <p>RootElement.java:</p>
  
  <pre><code>package org.example.domain;
  
  import javax.xml.bind.annotation.XmlElement;
  import javax.xml.bind.annotation.XmlRootElement;
  
  @XmlRootElement(namespace = "www.example.org/abc", name="Root_Element")
  public class RootElement {
    @XmlElement(namespace = "www.example.org/abc")
    public ChildElementWithXlink childElementWithXlink;
  
  }
  </code></pre>
  
  <p>ChildElementWithXLink.java:</p>
  
  <pre><code>package org.example.domain;
  
  import javax.xml.bind.annotation.XmlAttribute;
  import javax.xml.bind.annotation.XmlRootElement;
  import javax.xml.bind.annotation.XmlSchemaType;
  
  @XmlRootElement(namespace="www.example.org/abc", name="Child_Element_With_XLink")
  public class ChildElementWithXlink {
    @XmlAttribute(namespace = "http://www.w3.org/1999/xlink")
    @XmlSchemaType(namespace = "http://www.w3.org/1999/xlink", name = "anyURI")
    private String href="http://www.example.org";
  
  }
  </code></pre>
  
  <p>package-info.java:</p>
  
  <pre><code>@javax.xml.bind.annotation.XmlSchema(
      namespace = "http://www.example.org/abc",
      xmlns = {
            @javax.xml.bind.annotation.XmlNs(prefix = "abc", namespaceURI ="http://www.example.org/abc"),
            @javax.xml.bind.annotation.XmlNs(prefix = "xlink", namespaceURI = "http://www.w3.org/1999/xlink")
              }, 
      elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
      package org.example.domain;
  </code></pre>
  
  <p>Running Main.main() gives the following output:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;ns2:Root_Element xmlns:ns1="http://www.w3.org/1999/xlink" xmlns:ns2="www.example.org/abc"&gt;
  &lt;ns2:childElementWithXlink ns1:href="http://www.example.org"/&gt;
  &lt;/ns2:Root_Element&gt;
  </code></pre>
  
  <p>whereas what I would like is:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
  &lt;abc:Root_Element xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:abc="www.example.org/abc"&gt;
  &lt;abc:childElementWithXlink xlink:href="http://www.example.org"/&gt;
  &lt;/abc:Root_Element&gt;
  </code></pre>
  
  <p>Once this part is working, then the problem moves on to configuring the Jaxb2Marshaller in Spring (Spring 2.5.6, with spring-oxm-tiger-1.5.6 providing Jaxb2Marshaller) so that it provides the same by means of a simple context configuration and a call to marshal(). </p>
  
  <p>Thank you for your continued interest in this problem!</p>