2013-01-09 22 views
1

我想使用CDATA塊編組我的對象。我可以通過爲CharacterEscapeHandler創建編組和設置屬性來實現這一點(http://stackoverflow.com/questions/14193944/jaxb-marshalling-unmarshalling-with-cdata)。但在澤西島編組是由澤西島完成的。所以我怎麼能告訴澤西隊元帥與CDATA對象。使用Jersey Framework對CDATA進行編組

我具有以下服務

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

和豆類是

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; 
    } 
} 

我已經與添加適配器類試過。但問題是我怎樣才能將其他屬性設置爲球衣正在使用的默認編組器。

我想設置以下屬性。

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); } 
       }); 

回答