Here is the code which marshals java object into a SOAPMessage:
public static SOAPMessage encode(String key,Object object) throws JAXBException, SOAPException{
JAXBContext airContext = newInstance("com.test");
contextMap.put("ws", airContext);
Marshaller marshaller = airContext .createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage message = messageFactory.createMessage();
marshaller.marshal(object, message.getSOAPBody());
message.saveChanges();
return message;
}
and the object likes:
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Root {
private String name;
private String surname;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
}
I want to marshal it to this xml:
<root>
<name><![CDATA[test]]></name>
<surname>test</surname>
</root>
but now it displays as :
<root>
<name><![CDATA[test]]></name>
<surname>test</surname>
</root>
Could you please tell me what's wrong with it?