Serialize Jaxb Pojos to multiple or different namespaces
<p>Consider the following code:</p>

<pre><code>Main.java
====
package com.sample;

import com.sample.entity.Customer;
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(Customer.class);

       Customer customer = new Customer();
       customer.setId(123);

       Marshaller m = jc.createMarshaller();
       m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
       m.marshal(customer, System.out);    
    }
}


Customer.java
====
package com.sample.entity;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class Customer {
    private long id;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }
}

package-info.java
====
@XmlSchema(namespace = "http://www.example.org/package", elementFormDefault = XmlNsForm.QUALIFIED)
package com.sample.entity;

import javax.xml.bind.annotation.XmlSchema;
import javax.xml.bind.annotation.XmlNsForm;
</code></pre>

<p>I wish to reuse the Customer POJO and create two different namespace values. So first I wish to print the output </p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
&lt;customer xmlns="http://www.example.org/package"&gt;
    &lt;id&gt;123&lt;/id&gt;
&lt;/customer&gt;
</code></pre>

<p>like the current code does, then create a second xml with a different main namespace from the same pojo that will look like this</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
&lt;customer xmlns="http://www.another.org/package"&gt;
    &lt;id&gt;123&lt;/id&gt;
&lt;/customer&gt;
</code></pre>

<p>or remove the namespace all together</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
&lt;customer&gt;
    &lt;id&gt;123&lt;/id&gt;
&lt;/customer&gt;
</code></pre>