EDIT: here's the updated code https://github.com/MojoJojo/stackoverflow.34392476
Ok, here is a working version with all moxy_jaxb testing. Since you said you were using moxy, I did not account for the changes for model.sun packages. *. If you understand the concept below, you can easily fix it yourself.
First I cleared the namespace declarations in your mode. * packages. In most cases, declarations and bindings inside package-info.java are enough. Announcing them again and again in packages, entities, and fields will add complexity and undesirable behavior. See this link for more details. There is no need to re-declare them separately for the models / entities themselves, unless there is good reason for this. Further, the xml test itself was a bit broken. Fixed test xml with the necessary prefixes, where necessary:
Firstly, model.eclipselink.Document.java
@XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement(name = "document") public class Document { @XmlElement(name = "Export", namespace="urn:adcubum:Syrius") private Export export; public Export getExport() { return export; } public void setExport(Export export) { this.export = export; } }
model.eclipselink.package-info.java:
@XmlSchema(namespace = "http://www.adcubum.com/wsdl/global/callout/syrius/modul_bl/doc/service/documentrenderer/forwktbx", elementFormDefault = XmlNsForm.QUALIFIED) package model.eclipselink; import javax.xml.bind.annotation.XmlNs; import javax.xml.bind.annotation.XmlNsForm; import javax.xml.bind.annotation.XmlSchema;
Similar refactoring on model.eclipselink.export.packageinfo.java:
@XmlSchema(namespace = "urn:adcubum:Syrius", elementFormDefault = XmlNsForm.QUALIFIED) package model.eclipselink.export; import javax.xml.bind.annotation.XmlNs; import javax.xml.bind.annotation.XmlNsForm; import javax.xml.bind.annotation.Xml
And on Export.java:
package model.eclipselink.export; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlType; import org.eclipse.persistence.oxm.annotations.XmlElementNillable; @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement(name = "Export") @XmlType(name = "Export", propOrder = { "exportInhalt", "exportKopf", "schemaVersion" }) public class Export { @XmlElement(name = "ExportKopf", required = true) private ExportKopf exportKopf; @XmlElement(name = "ExportInhalt", required = true) private ExportInhalt exportInhalt; @XmlElement(name = "SchemaVersion", required = true) private String schemaVersion; public ExportKopf getExportKopf() { return exportKopf; } public void setExportKopf(ExportKopf exportKopf) { this.exportKopf = exportKopf; } public ExportInhalt getExportInhalt() { return exportInhalt; } public void setExportInhalt(ExportInhalt exportInhalt) { this.exportInhalt = exportInhalt; } public String getSchemaVersion() { return schemaVersion; } public void setSchemaVersion(String schemaVersion) { this.schemaVersion = schemaVersion; } }
And a few settings for your xml files for prefixes. Here document_prefix.xml
<?xml version="1.0" encoding="UTF-8"?> <for:document xmlns:for="http://www.adcubum.com/wsdl/global/callout/syrius/modul_bl/doc/service/documentrenderer/forwktbx"> <ns1:Export xmlns:ns1="urn:adcubum:Syrius"> <ns1:ExportKopf> <ns1:Quelle>lokal</ns1:Quelle> </ns1:ExportKopf> <ns1:ExportInhalt/> <ns1:SchemaVersion>bec811a9807a8c8da403d70b9b5e22ad</ns1:SchemaVersion> </ns1:Export> </for:document>
document.xml:
<?xml version="1.0" encoding="UTF-8"?> <for:document xmlns:for="http://www.adcubum.com/wsdl/global/callout/syrius/modul_bl/doc/service/documentrenderer/forwktbx" xmlns="urn:adcubum:Syrius"> <Export> <ExportKopf> <Quelle>lokal</Quelle> </ExportKopf> <ExportInhalt /> <SchemaVersion>bec811a9807a8c8da403d70b9b5e22ad</SchemaVersion> </Export> </for:document>
and document_realnamespace.xml (I don't know what the purpose of this file is):
<?xml version="1.0" encoding="UTF-8"?> <for:document xmlns:ns1="urn:adcubum:Syrius" xmlns:for="http://www.adcubum.com/wsdl/global/callout/syrius/modul_bl/doc/service/documentrenderer/forwktbx"> <ns1:Export> <ns1:ExportKopf> <ns1:Quelle>lokal</ns1:Quelle> </ns1:ExportKopf> <ns1:ExportInhalt/> <ns1:SchemaVersion>bec811a9807a8c8da403d70b9b5e22ad</ns1:SchemaVersion> </ns1:Export> </for:document>
And you run mvn clean test:
Running moxy_jaxb.MarshallerTest Context class: class org.eclipse.persistence.jaxb.JAXBContext <?xml version="1.0" encoding="UTF-8"?> <document xmlns="http://www.adcubum.com/wsdl/global/callout/syrius/modul_bl/doc/service/documentrend erer/forwktbx" xmlns:ns0="urn:adcubum:Syrius"> <ns0:Export> <ns0:ExportInhalt/> <ns0:ExportKopf> <ns0:Quelle>lokal</ns0:Quelle> </ns0:ExportKopf> <ns0:SchemaVersion>bec811a9807a8c8da403d70b9b5e22ad</ns0:SchemaVersion> </ns0:Export> </document> Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.044 sec Running moxy_jaxb.UnmarshallerTest Context class: class org.eclipse.persistence.jaxb.JAXBContext lokal Context class: class org.eclipse.persistence.jaxb.JAXBContext lokal Context class: class org.eclipse.persistence.jaxb.JAXBContext lokal Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.033 sec