我在Windows 10上运行的Java 1.8.0_191程序中获得以下UnmarshalException,该程序使用通过jaxb2 Maven插件版本2.5.0生成的类来处理传入的XML SOAP请求:
JAXB unmarshalling exception; nested exception is javax.xml.bind.UnmarshalException with linked exception:
[org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 622; cvc-complex-type.2.4.a : Contenu non valide trouvé à partir del'élément 'MotifCommande'. L'une des valeurs '{AliasCde,RefExterneCde, DateDepot}' est attendue.]
以下是异常消息的英文快速翻译:
从MotifCommand项开始发现无效的内容。其中一个项目'{AliasCd,RefExterneCde,DateDepot}'是预期的。
奇怪的是,项目列表提到了两个可选字段(AliasCD和RefExterneCde)和一个必填字段(DateDepot)。为什么不只是必填字段?
此外,为什么消息从MotifCommande标记开始就声明内容无效,尽管MotifCommande标记在XSD中(强制性)DateDepot标记出现在[[after之后?
XSD和SOAP请求以zip格式提供,在此网站上:https://github.com/highsource/maven-jaxb2-plugin/issues/185非常感谢您的帮助。
<xsd:sequence>
<xsd:element name="SystemeRefCde" type="xsd:string" minOccurs="1"/>
<xsd:element name="AliasCde" minOccurs="0" maxOccurs="unbounded">
<xsd:element name="RefExterneCde" minOccurs="0" maxOccurs="unbounded">
<xsd:element name="DateDepot" type="xsd:string" minOccurs="1"/>
<!-- ... -->
<xsd:element name="MotifCommande" type="xsd:string" minOccurs="0"/>
您正在使用序列。因此,项目的顺序是相关的。这意味着,在SystemeRefCde
之后仅是光学元素AliasCde
或RefExterneCde
,在这些元素之后,可能会出现强制元素DateDepot
。每隔一个元素就会导致架构冲突。
在您的请求中,您有:
<RefCommande>32R69010200004101415</RefCommande> <SystemeRefCde>32R</SystemeRefCde> <MotifCommande>ORDST</MotifCommande>
SystemeRefCde
之后,序列中的下一个元素是MotifCommande
。 XSD不允许这样做。您之间至少缺少必需的DateDepot
元素。