title: How to remove namespace from generated JAXB
body: <p>Using JAVA 7, XJC.</p>
  
  <p>The xsd is provided by a 3rd party that uses .NET.</p>
  
  <p>The issue at hand is that when I marshal the object into XML I get something along these lines:</p>
  
  <pre><code>&lt;SalesOrder xmlns:ns2="http://schemas.datacontract.org/2004/07/RKLServiceQueue"&gt;
    &lt;ns2:BillToAddrLine1&gt;7315 N Ritter Ave&lt;/ns2:BillToAddrLine1&gt;
    &lt;ns2:BillToAddrLine2&gt;&lt;/ns2:BillToAddrLine2&gt;
    &lt;ns2:BillToAddrName&gt;David Kruse&lt;/ns2:BillToAddrName&gt;
    &lt;ns2:BillToCity&gt;Indianapolis&lt;/ns2:BillToCity&gt;
    &lt;ns2:BillToCountryID&gt;USA&lt;/ns2:BillToCountryID&gt;
    &lt;ns2:BillToPostalCode&gt;46250&lt;/ns2:BillToPostalCode&gt;
  &lt;/SalesOrder
  </code></pre>
  
  <p>The service is expecting something like this:
  </p>
  
  <pre><code>  &lt;SalesOrder xmlns="http://schemas.datacontract.org/2004/07/RKLServiceQueue"&gt;
      &lt;BillToAddrLine1&gt;String content&lt;/BillToAddrLine1&gt;
      BillToAddrLine2&gt;String content&lt;/BillToAddrLine2&gt;
      &lt;BillToAddrLine3&gt;String content&lt;/BillToAddrLine3&gt;
      &lt;BillToAddrLine4&gt;String content&lt;/BillToAddrLine4&gt;
      &lt;BillToAddrLine5&gt;String content&lt;/BillToAddrLine5&gt;
      &lt;BillToAddrName&gt;String content&lt;/BillToAddrName&gt;
      &lt;BillToCity&gt;String content&lt;/BillToCity&gt;
    &lt;/SalesOrder&gt;
  </code></pre>
  
  <p>Here is part of the xsd as well
  </p>
  
  <pre><code>&lt;xs:schema xmlns:tns="http://schemas.datacontract.org/2004/07/RKLServiceQueue" elementFormDefault="qualified" targetNamespace="http://schemas.datacontract.org/2004/07/RKLServiceQueue" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
    &lt;xs:complexType name="SalesOrder"&gt;
      &lt;xs:sequence&gt;
        &lt;xs:element minOccurs="0" name="BillToAddrLine1" nillable="true" type="xs:string" /&gt;
        &lt;xs:element minOccurs="0" name="BillToAddrLine2" nillable="true" type="xs:string" /&gt;
        &lt;xs:element minOccurs="0" name="BillToAddrLine3" nillable="true" type="xs:string" /&gt;
        &lt;xs:element minOccurs="0" name="BillToAddrLine4" nillable="true" type="xs:string" /&gt;
        &lt;xs:element minOccurs="0" name="BillToAddrLine5" nillable="true" type="xs:string" /&gt;
        &lt;xs:element minOccurs="0" name="BillToAddrName" nillable="true" type="xs:string" /&gt;
        &lt;xs:element minOccurs="0" name="BillToCity" nillable="true" type="xs:string" /&gt;
        &lt;xs:element minOccurs="0" name="BillToCountryID" nillable="true" type="xs:string" /&gt;
        &lt;xs:element minOccurs="0" name="BillToPostalCode" nillable="true" type="xs:string" /&gt;
        &lt;xs:element minOccurs="0" name="BillToStateID" nillable="true" type="xs:string" /&gt;
  </code></pre>
  
  <p>I have conducted test on SoapUI to verify.</p>
  
  <p>I have done a bit of searching on the web, including stackoverflow and it points to using NamespacePrefixMapper but that does not seem to do the the trick.  I keep getting the following exception:</p>
  
  <pre><code>javax.xml.bind.PropertyException: name: com.sun.xml.internal.bind.marshaller.namespacePrefixMapper value: com.heritage.jobs.MyPrefixMapper@29545330 
  </code></pre>
  
  <p>Here is the mapper</p>
  
  <pre class="lang-java prettyprint-override"><code>import com.sun.xml.internal.bind.marshaller.NamespacePrefixMapper;
  
  
  /**
   * 
   */
  public class MyPrefixMapper extends NamespacePrefixMapper
  {
      private static final String FOO_PREFIX = ""; // DEFAULT NAMESPACE
      private static final String FOO_URI = "http://schemas.datacontract.org/2004/07/RKLServiceQueue";
  
  
      /*
       * (non-Javadoc)
       * 
       * @see com.sun.xml.internal.bind.marshaller.NamespacePrefixMapper#getPreferredPrefix(java.lang.String,
       * java.lang.String, boolean)
       */
      @Override
      public String getPreferredPrefix(final String pNameSpaceUri, final String pSuggestion, final boolean pRequirePrefix)
      {
          if (FOO_URI.equals(pNameSpaceUri))
          {
              return FOO_PREFIX;
          }
  
          return pSuggestion;
      }
  </code></pre>
  
  <p>Here is what I am using to call it:</p>
  
  <pre class="lang-java prettyprint-override"><code>final JAXBContext context = JAXBContext.newInstance(SalesOrder.class);
  
  marshaller = context.createMarshaller();
  marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
  marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
  
  final MyPrefixMapper prefixMapper = new MyPrefixMapper();
  try
  {
          marshaller.setProperty("com.sun.xml.internal.bind.marshaller.namespacePrefixMapper", prefixMapper);
  }
  catch (final PropertyException e)
  {
  LOG.error("perform(CronJobModel)", e);
  }
  </code></pre>
  
  <p>I am not clear as to what I am missing to make this work - How can I remove the namespace ns from each of the fields/properties? </p>