【发布时间】:2017-11-01 20:12:40
【问题描述】:
我在 JAX-WS 中有一个 Web 服务,并且 pom.xml 中的 maven 目标('ws-jwsc') 生成 WSDL 文件以及输入和输出 XSD。
我想以不同的方式将 java 类的属性映射到 WSDL/XSD 模式,如下所示:
我有两个类 1) 客户 2) 位置
1.客户 - 客户特定信息
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Customer {
public Customer() {
super();
}
public Customer(CustomerType customerType) {
this.customerType = customerType;
}
public enum CustomerType {
B, S, C
}
private CustomerType customerType;
private String name;
private Long accountNumber;
private Location location;
// getter/setter for properties
}
2。 Location - 要包含 addr1/addr2/city/state/zip/country 的位置对象
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Location {
private String address1;
private String address2;
private String city;
private String state;
private String zip;
private String country;
/**
* @return the city
*/`enter code here`
public String getCity() {
return city;
}
//getter/setter for properties
}
现在我的问题是在运行时 Customer 类中的“customerType”属性可以有 3 个值('B','C','S')
所以,
例如,如果 customerType 的 runTime 值为“S”。
然后代码将分别在 SOAP 响应 XML 中生成 Location 对象属性为 'ShipperAddress1', 'ShipperAddress2', 'ShipperCity', 'ShipperState', 'ShipperZip', 'ShipperCountry' for 'address1' , 'address2', 'city', 'state', 'zip' and 'country'properties。
示例 2:如果 customerType 的 runTime 值为 'C'。
然后代码将分别在 SOAP 响应 XML 中生成 Location 对象属性为 'ConsigneeAddress1', 'ConsigneeAddress2', 'ConsigneeCity', 'ConsigneeState', 'ConsigneeZip', 'ConsigneeCountry' for 'address1' , 'address2', 'city', 'state', 'zip' and 'country' 属性。
我需要知道是否可以这样做,如果可以,那么如何? 非常感谢所有帮助。
【问题讨论】:
标签: java xml jaxb marshalling