/ / JAXB आउटपुट समस्याएँ: अजीब अपवाद - jaxb, marshalling, xml- बाइंडिंग

JAXB निर्गम मुद्दों: अजीब अपवाद-JAXB, मार्शलिंग, xml-बाइंडिंग

javax.xml.bind।MarshalException - जुड़े अपवाद के साथ: : com.sun.xml.bind.v2.runtime.MarshallerImpl.राइट पर कॉम पर

यहाँ मेरा कोड स्निपेट है:

OutputStream output = new ByteArrayOutputStream();
XMLOutputFactory xof = XMLOutputFactory.newInstance();
XMLStreamWriter xsw = xof.createXMLStreamWriter(output);


QName root = new QName("return");
JAXBElement<Customer> je = new JAXBElement<Customer>(root, Customer.class, customer);

xsw.writeStartDocument();
xsw.setDefaultNamespace("S");
xsw.writeStartElement("S", "Envelope", "http://schemas.xmlsoap.org/soap/envelope/");
xsw.writeStartElement("S", "Body", "http://schemas.xmlsoap.org/soap/envelope/");
xsw.writeStartElement("ns0", "findCustomerResponse", "http://service.jaxws.blog/");

context = JAXBContext.newInstance(Customer.class);
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
marshaller.marshal(je, xsw);
xsw.writeEndDocument();
xsw.close();
if(output != null)
return output.toString();

क्या आपके पास कोई विचार है कि ऐसा क्यों होता है? अग्रिम में धन्यवाद

उत्तर:

जवाब के लिए 0 № 1

आपको निर्दिष्ट करने की आवश्यकता है JAXB_FRAGMENT पर संपत्ति Marshaller इस समस्या से बचने के लिए। यह संपत्ति JAXB को यह बताती है कि यह दस्तावेज़ के बीच में है और इसे हेडर लिखना नहीं चाहिए।

अधिक जानकारी के लिए