【发布时间】:2011-04-22 09:08:06
【问题描述】:
我目前正在学习 JAXB 和 Web Service,但我遇到了这个我不知道的问题 如何解决。
假设我有一个用 JAXB 注释的非常简单的类。
@XmlRootElement
public class Customer {
private int custID;
private String custName;
//getters and setters
}
我有这个类,我将其作为 Web 服务公开。 (注意:为了简单起见,我在这里对所有内容进行了硬编码 但这会连接到数据库)
@WebService
public class CustomerWS {
@WebMethod(operationName = "customerData")
public Customer getCustomer(){
Customer cust = new Customer();
cust.setCustID(12345);
cust.setCustName("John Doe");
return cust;
}
}
SOAP 信封响应是这样的。
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:customerDataResponse xmlns:ns2="http://test.com/">
<return>
<custID>12345</custID>
<custName>John Doe</custName>
</return>
</ns2:customerDataResponse>
</S:Body>
</S:Envelope>
现在假设我在客户实体中有另一个名为 status 的属性,他们希望这个属性作为肥皂的属性 响应如下所示,而不是成为客户元素的一部分。 (A = 活跃,I = 不活跃)
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:customerDataResponse status="A" xmlns:ns2="http://test.com/">
<return>
<custID>12345</custID>
<custName>John Doe</custName>
</return>
</ns2:customerDataResponse>
</S:Body>
</S:Envelope>
@XmlRootElement
public class Customer {
private int custID;
private String custName;
//Another Annotation??? (A or I only)
private String status;
//getters and setters
}
如何注释我的类以满足此要求?谢谢
【问题讨论】:
标签: java web-services soap jaxb jax-ws