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」。嘗試在元素中指定它們。 –