I try to unmarshal a simple xml document:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <for:document xmlns:for="http://www.adcubum.com/wsdl/global/callout/syrius/modul_bl/doc/service/documentrenderer/forwktbx"> <Export xmlns="urn:adcubum:Syrius"> <ExportInhalt/> <ExportKopf> <Quelle>lokal</Quelle> </ExportKopf> <SchemaVersion>bec811a9807a8c8da403d70b9b5e22ad</SchemaVersion> </Export> </for:document> This is the document I get from following code:
Document document = new Document(); Export export = new Export(); ExportKopf exportKopf = new ExportKopf(); exportKopf.setQuelle("lokal"); export.setExportKopf(exportKopf); ExportInhalt exportInhalt = new ExportInhalt(); export.setExportInhalt(exportInhalt); export.setSchemaVersion("bec811a9807a8c8da403d70b9b5e22ad"); document.setExport(export); JAXBContext jaxbContext = JAXBContext.newInstance(Document.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(document, System.out); Document looks as follows:
@XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement(name = "document", namespace = "http://www.adcubum.com/wsdl/global/callout/syrius/modul_bl/doc/service/documentrenderer/forwktbx") public class Document { @XmlElement(name = "Export", namespace = "urn:adcubum:Syrius") private vo.dom.common_service.modul_bl.syrius.Export export; } package-info.java
@XmlSchema( namespace = "urn:adcubum:Syrius", xmlns = { @XmlNs(prefix = "for", namespaceURI = "http://www.adcubum.com/wsdl/global/callout/syrius/modul_bl/doc/service/documentrenderer/forwktbx"), @XmlNs(prefix = "", namespaceURI = "urn:adcubum:Syrius") }, elementFormDefault = XmlNsForm.UNQUALIFIED) When I try to unmarshal it, I don't get the data mapped:
JAXBContext jaxbContext = JAXBContext.newInstance(Document.class); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); InputStream is = this.getClass().getResourceAsStream("/requests/document_simple3.xml"); XMLInputFactory factory = XMLInputFactory.newInstance(); XMLStreamReader xmlsr = factory.createXMLStreamReader(is); Document document = unmarshaller.unmarshal(xmlsr, Document.class).getValue(); ExportKopf and ExportInhalt are returning null.
Instead following xml works. The only difference is the namespace prefix:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <for:document xmlns:for="http://www.adcubum.com/wsdl/global/callout/syrius/modul_bl/doc/service/documentrenderer/forwktbx"> <ns3:Export xmlns:ns3="urn:adcubum:Syrius"> <ExportInhalt/> <ExportKopf> <Quelle>lokal</Quelle> </ExportKopf> <SchemaVersion>bec811a9807a8c8da403d70b9b5e22ad</SchemaVersion> </ns3:Export> </for:document> I am using eclipselink moxy.
What do I have to change, so that unmarshaling the marshaled document works.
No comments:
Post a Comment