I'm doing a WSDL client and want to know how I can set an XML element to be CDATA.
I'm using the wsimport
to generate the source code, and the CDATA element is part of the request XML.
This is the XML class of the request:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = { "dataRequest" })
@XmlRootElement(name = "ProcessTransaction")
public class ProcessTransaction {
protected String dataRequest;
public String getDataRequest() {
return dataRequest;
}
public void setDataRequest(String value) {
this.dataRequest = value;
}
}
I've already tried the @XmlAdapter, but it changes nothing on the output...
import javax.xml.bind.annotation.adapters.XmlAdapter;
public class AdaptorCDATA extends XmlAdapter<String, String> {
@Override
public String marshal(String arg0) throws Exception {
return "<![CDATA[" + arg0 + "]]>";
}
@Override
public String unmarshal(String arg0) throws Exception {
return arg0;
}
}
In the XML class:
@XmlJavaTypeAdapter(value=AdaptorCDATA.class)
protected String dataRequest;
I tried to debug, but it never steps on the AdaptorCDATA
function.
The wsimport
version is 2.2.9
and the jaxb-api
version is 2.1
.
marshall()
-method. Looking at your question I see that you have a snippet where you have the@XmlJavaTypeAdapter
-Annotation but not in theProcessTransaction
-class where it should be. If you have it there but the breakpoint is still not hit, maybe you have to rebuild and refresh before firing up the client? – HortensehortensiaCharacterEscapeHandler
for marshaller, that's why you get all CDATA escaped. Check rest of https://mcmap.net/q/447594/-jaxb-marshalling-unmarshalling-with-cdata And AFAIK wsimport doesn't support setting marshaller property for client. CXF client support it cxf.apache.org/docs/jaxb.html – Xanthene