2

i want to marshal my object using CDATA block. i can do this with creating marshaller and setting property for CharacterEscapeHandler(http://stackoverflow.com/questions/14193944/jaxb-marshalling-unmarshalling-with-cdata). but in Jersey marshalling is done by jersey. so how can i tell jersey to marshal object with CDATA.

i have following service

@GET
    @Path("/getdata")
    @Produces(MediaType.TEXT_XML)
    public HelloBean getData() throws Exception 
    {
        HelloBean h1 = new HelloBean();
        h1.setName("kshitij");
        return h1;
    }

and bean Class is

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "root")
@XmlAccessorType(XmlAccessType.FIELD)
public class HelloBean {

    private String name;

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
}

i have tried with adding Adaptor class. but problem is how can i set additional property to default marshaller which jersey is using.

i want to set following property.

 marshaller.setProperty(CharacterEscapeHandler.class.getName(), new CharacterEscapeHandler() { 
                public void escape(char[] ac, int i, int j, boolean flag,
                Writer writer) throws IOException {
                writer.write( ac, i, j ); }
                });
MRX
  • 1,611
  • 8
  • 33
  • 55

1 Answers1

0

You can create a JAX-RS MessageBodyWriter. A MessageBodyWriter allows you use your own code to write the XML message.

Related Example

Community
  • 1
  • 1
bdoughan
  • 147,609
  • 23
  • 300
  • 400
  • 1
    I have done it with implementing ContextResolver and changing runtime implementation(with jaxb-impl-2.2). – MRX Jan 09 '13 at 13:01