为什么这个架构:
<xsd:complexType name="ErrType">
<xsd:sequence minOccurs="0" maxOccurs="unbounded">
<xsd:element name="errorCode" type="xsd:string"/>
<xsd:element name="errorDescription" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
生成此Java代码:
class ErrType {
@XmlElementRefs({
@XmlElementRef(name = "errorCode", namespace = "http://somewhere/blah.xsd", type = JAXBElement.class),
@XmlElementRef(name = "errorDescription", namespace = "http://somewhere/blah.xsd", type = JAXBElement.class)
})
protected List<JAXBElement<String>> errorCodeAndErrorDescription;
// ...
}
我原本期望的更像是:
class ErrType extends ArrayList<ErrTypeEntry> {}
class ErrTypeEntry {
protected String errorCode
protected String errorDescription;
}
好的,所以我猜答案是:因为它确实如此。将两个字段组合成一个字段似乎非常不合需要。它不必要地删除了重要的结构。
答案 0 :(得分:1)
我的猜测是,您必须更多地编写您的架构,以便更接近(结构上)您的期望:
<xsd:complexType name="ErrTypeEntry">
<xsd:sequence>
<xsd:element name="errorCode" type="xsd:string"/>
<xsd:element name="errorDescription" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Errors">
<xsd:sequence>
<xsd:element name="error" type="ErrTypeEntry" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>