我有一个场景,我想让所有返回对象继承基类。在下面的场景中,BaseResponse是webservice返回的所有响应的基类。将有许多webmethods,每个人都将拥有它自己的返回对象。一个这样的例子在下面的代码中
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "BaseResponse", propOrder = { "state"})
public class BaseResponse {
private Integer state;
public Integer getState(){
return state;
}
public void setState(Integer state){
this.state = state;
}
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "XXXActionResponse ", propOrder = { "data1", "data2"})
public class XXXActionResponse extends BaseResponse {
private String data1;
private String data2;
public String getData1(){
return data1;
}
public String getData2(){
return data2;
}
public void setData1(String data1){
this.data1=data1;
}
public void setData2(String data2){
this.data2 = data2;
}
}
我的网络服务
@WebService
public class MyService{
@WebMethod
public XXXActionResponse DoXXXAction()
throws Exception {
XXXActionResponse resp = new XXXActionResponse();
resp.setData1("Data1");
resp.setData2("Data2");
resp.setState(0);
Return resp;
}
这是创建只有Data1和Data2的Jaxb对象。 请解释如何序列化state属性?
此致 拉维