我想使用CDATA块封送我的对象。我可以通过为CharacterEscapeHandler创建marshaller和设置属性来做到这一点(http://stackoverflow.com/questions/14193944/jaxb-marshalling-unmarshalling-with-cdata)。但在泽西岛,编组是由球衣完成的。那么如何用CDATA告诉球衣编组对象。
我有以下服务
@GET
@Path("/getdata")
@Produces(MediaType.TEXT_XML)
public HelloBean getData() throws Exception
{
HelloBean h1 = new HelloBean();
h1.setName("kshitij");
return h1;
}
和bean类是
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;
}
}
我尝试过添加Adapter类。但问题是如何将其他属性设置为泽西使用的默认编组。
我想设置以下属性。
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 ); }
});
答案 0 :(得分:0)
您可以创建JAX-RS MessageBodyWriter
。 MessageBodyWriter
允许您使用自己的代码编写XML消息。
相关示例