[英]Why would JAXB generate single List<JAXBElement<String>> field from two fields in the Schema?
Why would this Schema: 为什么这个模式:
<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>
Generate to this Java code: 生成此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;
// ...
}
I would have expected something more like: 我本来期望更像:
class ErrType extends ArrayList<ErrTypeEntry> {}
class ErrTypeEntry {
protected String errorCode
protected String errorDescription;
}
Okay, so I guess the answer is: because it does. 好的,我想答案是:因为确实如此。 Combining two fields into a single one seems very undesirable.
将两个字段合并为一个字段似乎是非常不可取的。 It removed important structure unnecessarily.
它不必要地删除了重要的结构。
My guess is that you'd have to write your schema a bit more like this to get something closer (structurally) to your expectations: 我的猜测是,您必须像这样编写模式,以使(结构上)更接近您的期望:
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.