XML strings in JAXB
I have a JPA entity class mimicking a table. Something like this:
@XmlType(name="MyClassElementType")
public class MyClass {
String name;
String xmlDesc;
public MyClass() {}
@XmlElement
String getName() { return name; }
void setName(String name) { this.name = name; }
@XmlElement
String getXmlDesc() { return xmlDesc; }
void setXmlDesc(String xmlDesc) { this.xmlDesc = xmlDesc; }
}
In a Jersey REST get call I'm trying to return this class:
@Get
@Produces("application/xml")
public MyClass get() {
return myClass;
}
Now I'm expecting the already xml string(xmlStr) to be returned as is, but Jersey/JAXB escape开发者_如何学编程s it...
So anyway around this?
JAXB has no way of knowing that xmlDesc
contains an XML string, it could be anything, so it has to escape it.
If you want to store arbitrary XML in a JAXB object model, you need to store it as an instance of org.w3c.dom.Element
. JAXB should then convert that to/from XML as necessary.
精彩评论