tags:

views:

52

answers:

1

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 escapes it...

So anyway around this?

+1  A: 

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.

skaffman
thought so... thanks for yr answer. Let me go and try that...
OOO
@OOO: You'll need to use `@XmlAnyElement` rather than `@XmlElement`
skaffman