title: Jaxb ignore the namespace on unmarshalling
body: <p>I use Jaxb2 and Spring. I am trying to unmarshal some XML that are sent by 2 of my customers. </p>
  
  <p>Up to now, I only had to handle one customer which sent some xml like this : </p>
  
  <pre><code>&lt;foo xmlns="com.acme"&gt;
    &lt;bar&gt;[...]&lt;/bar&gt;
  &lt;foo&gt;
  </code></pre>
  
  <p>that is bound to a POJO like this : </p>
  
  <pre><code>@XmlType(name = "", propOrder = {"bar"})
  @XmlRootElement(name = "Foo")
  public class Foo {
  
    @XmlElement(name = "Bar")
    private String bar;
  
    [...]
  }
  </code></pre>
  
  <p>I discovered that the previous developer hardcoded the namespace in the unmarshaller in order to make it work.</p>
  
  <p>Now, the second customer sends the same XML but changes the namespace!</p>
  
  <pre><code>&lt;foo xmlns="com.xyz"&gt;
    &lt;bar&gt;[...]&lt;/bar&gt;
  &lt;foo&gt;
  </code></pre>
  
  <p>Obviously, the unmarshaller fails to unmarshall because it expects some <code>{com.acme}foo</code> instead of <code>{com.xyz}foo</code>. Unforunately, asking the customer to change the XML is not an option.</p>
  
  <p><strong>What I tried :</strong> </p>
  
  <p><strong>1)</strong> In <code>application-context.xml</code>, I searched for a configuration which would allow me to ignore the namespace but could not find one : </p>
  
  <pre><code>&lt;bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"&gt;
    &lt;property name="packagesToScan"&gt;
      &lt;list&gt;
        &lt;value&gt;com.mycompany.mypkg&lt;/value&gt;
      &lt;/list&gt;
    &lt;/property&gt;
    &lt;property name="marshallerProperties"&gt;
      &lt;map&gt;
        &lt;entry key="???"&gt;&lt;value type="java.lang.Boolean"&gt;false&lt;/value&gt;&lt;/entry&gt;
      &lt;/map&gt;
    &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>it seems that the only available options are the ones listed in the Jaxb2Marshaller's Javadoc : </p>
  
  <pre><code>/**
   * Set the JAXB {@code Marshaller} properties. These properties will be set on the
   * underlying JAXB {@code Marshaller}, and allow for features such as indentation.
   * @param properties the properties
   * @see javax.xml.bind.Marshaller#setProperty(String, Object)
   * @see javax.xml.bind.Marshaller#JAXB_ENCODING
   * @see javax.xml.bind.Marshaller#JAXB_FORMATTED_OUTPUT
   * @see javax.xml.bind.Marshaller#JAXB_NO_NAMESPACE_SCHEMA_LOCATION
   * @see javax.xml.bind.Marshaller#JAXB_SCHEMA_LOCATION
   */
  public void setMarshallerProperties(Map&lt;String, ?&gt; properties) {
      this.marshallerProperties = properties;
  }
  </code></pre>
  
  <p><strong>2)</strong> I also tried to configure the unmarshaller in the code : </p>
  
  <pre><code>try {
    jc = JAXBContext.newInstance("com.mycompany.mypkg");
  
    Unmarshaller u = jc.createUnmarshaller();
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(false);//Tried this option.
  
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.parse(xmlFile.toFile());
    u.unmarshal(new DOMSource(doc));
    return (Foo)u.unmarshal(new StreamSource(xmlFile.toFile()));
  } catch (ParserConfigurationException | SAXException | IOException | JAXBException e) {
    LOGGER.error("Erreur Unmarshalling CPL");
  }
  </code></pre>
  
  <p><strong>3)</strong> Different form with a SAXParser : </p>
  
  <pre><code>try {
    jc = JAXBContext.newInstance("com.mycompany.mypkg");
    Unmarshaller um = jc.createUnmarshaller();
    final SAXParserFactory sax = SAXParserFactory.newInstance();
    sax.setNamespaceAware(false);
    final XMLReader reader = sax.newSAXParser().getXMLReader();
    final Source er = new SAXSource(reader, new InputSource(new FileReader(xmlFile.toFile())));
    return (Foo)um.unmarshal(er);
  }catch(...) {[...]}
  </code></pre>
  
  <p><strong>This one works!</strong> But still, I would prefer to be able to autowire the Unmarshaller without needing this ugly conf everytime.</p>