Заставить JAXB добавлять префикс динамического пространства имен ко всем дочерним элементам. ⇐ JAVA
Заставить JAXB добавлять префикс динамического пространства имен ко всем дочерним элементам.
I have a object structure some parts are reused with different namespaces. For these cases I need to set the namespace on the field in the object it occurs and have the namespace prefix added to all child elements. I would like to accomplish this with field annotations.
The objects are used in a SOAP message.
Example classes:
package some.package; Class MyObject { @XmlElement(name = "fieldA") private String fieldA; @XmlElement(name = "fieldB") private String fieldB; } package some.other.package; @XmlRootElement(name = "rootA", namespace = "namspace-a") Class RootA { @XmlElement(name = "myObject", namespace = "namspace-a") private MyObject myObject; } package some.third.package; @XmlRootElement(name = "rootB", namespace = "namspace-b") Class RootB { @XmlElement(name = "myObject", namespace = "namspace-b") private MyObject myObject; } Expected output when marshalling objects of type RootA and RootB:
aaaa bbbb aaaa bbbb Actual output (RootA example):
aaaa bbbb Since the namspace needs to be dynamic in the sense that it depends on where the object is used, it cannot be solved with package-info or any annotations in the MyObject class.
The marshalling is generic for many different classes/requests and cannot know about specifics of different objects.
Code used for marshalling:
MessageFactory mf = MessageFactory.newInstance(); SOAPMessage sm = mf.createMessage(); SOAPPart sp = sm.getSOAPPart(); SOAPEnvelope se = sp.getEnvelope(); Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); JAXBContext context = getJAXBContext(); // Gets a JAXBContext for all relevant classes Marshaller m = context.createMarshaller(); JAXBElement req = new JAXBElement(operation.getQname(), operation.getRequestClass(), request); // operation has information about the top level object m.marshal(req, doc); se.getBody().addDocument(doc); sm.saveChanges(); ByteArrayOutputStream s = new ByteArrayOutputStream(); sm.writeTo(s); return s.toString(); Is this possible?
Источник: https://stackoverflow.com/questions/781 ... d-elements
I have a object structure some parts are reused with different namespaces. For these cases I need to set the namespace on the field in the object it occurs and have the namespace prefix added to all child elements. I would like to accomplish this with field annotations.
The objects are used in a SOAP message.
Example classes:
package some.package; Class MyObject { @XmlElement(name = "fieldA") private String fieldA; @XmlElement(name = "fieldB") private String fieldB; } package some.other.package; @XmlRootElement(name = "rootA", namespace = "namspace-a") Class RootA { @XmlElement(name = "myObject", namespace = "namspace-a") private MyObject myObject; } package some.third.package; @XmlRootElement(name = "rootB", namespace = "namspace-b") Class RootB { @XmlElement(name = "myObject", namespace = "namspace-b") private MyObject myObject; } Expected output when marshalling objects of type RootA and RootB:
aaaa bbbb aaaa bbbb Actual output (RootA example):
aaaa bbbb Since the namspace needs to be dynamic in the sense that it depends on where the object is used, it cannot be solved with package-info or any annotations in the MyObject class.
The marshalling is generic for many different classes/requests and cannot know about specifics of different objects.
Code used for marshalling:
MessageFactory mf = MessageFactory.newInstance(); SOAPMessage sm = mf.createMessage(); SOAPPart sp = sm.getSOAPPart(); SOAPEnvelope se = sp.getEnvelope(); Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); JAXBContext context = getJAXBContext(); // Gets a JAXBContext for all relevant classes Marshaller m = context.createMarshaller(); JAXBElement req = new JAXBElement(operation.getQname(), operation.getRequestClass(), request); // operation has information about the top level object m.marshal(req, doc); se.getBody().addDocument(doc); sm.saveChanges(); ByteArrayOutputStream s = new ByteArrayOutputStream(); sm.writeTo(s); return s.toString(); Is this possible?
Источник: https://stackoverflow.com/questions/781 ... d-elements
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Заставить JAXB добавлять префикс динамического пространства имен ко всем дочерним элементам.
Anonymous » » в форуме JAVA - 0 Ответы
- 76 Просмотры
-
Последнее сообщение Anonymous
-