1
为什么会这样架构:为什么JAXB会从Schema中的两个字段中生成单个List <JAXBElement <String>>字段?
<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;
}
好了,所以我想答案是:因为它。将两个字段组合成一个字段似乎是非常不可取的。它不必要地删除了重要的结构。
什么是生成的代码的问题?你会期待什么? – Attila
也许是因为您在序列元素上指定了minOccurs =“0”maxOccurs =“unbounded”。尝试在元素中指定它们。 –