I generate Java files from an XSD using namespaces. When the corresponding Java objects are serialized to XML the namespaces prefixes are ns1
, ns2
... There seems to be three ways to control the prefixes:
- If using Oracle's Java one can add an implementation of the internal class
com.sun.xml.internal.bind.marshaller.NamespacePrefixMapper
to the marshaller. - If the file
package-info.java
is under your control then you can add the annotationjavax.xml.bind.annotation.XmlNs
to it. This does not work when the Java files are generated from a XSD. - You can add a third party tool and configure the
javax.xml.bind.annotation.XmlNs
annotation in the JAXB binding file.
The 3rd option is non standard and its last version is from 2012. Is there an equivalent standard option available in the meantime, e.g. an element or attribute in the standard namespaces http://java.sun.com/xml/ns/jaxb
or http://java.sun.com/xml/ns/jaxb/xjc
?