我正在从 XSD 为我正在为其构建客户端的 SOAP WebService 生成 JAXB 类(使用 jaxws-maven-plugin v2.4.1,wsimport 目标生成)。
我遇到了一个问题,即在编组对象时 JAXB 不会将 xsi:type-Information 添加到抽象类型的节点。WebService 现在(我认为这是正确的)抱怨我试图传递它元素而不指定它们是什么类型(“元素的类型定义不能是抽象的......”)。
这是一个演示我的问题的简化示例:
抽象类型架构:(abstract.xsd)
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://www.example.com/namespace_abstract"
elementFormDefault="qualified"
attributeFormDefault="qualified"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.example.com/namespace_abstract">
<xsd:complexType name="ElementType" abstract="true">
<xsd:simpleContent>
<xsd:extension base="xsd:string"/>
</xsd:simpleContent>
</xsd:complexType>
</xsd:schema>
Run Code Online (Sandbox Code Playgroud)
具体类型架构:(concrete.xsd)
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://www.example.com/namespace_concrete"
elementFormDefault="qualified"
attributeFormDefault="qualified"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.example.com/namespace_concrete"
xmlns:abstr="http://www.example.com/namespace_abstract">
<xsd:import namespace="http://www.example.com/namespace_abstract" schemaLocation="abstract.xsd"/>
<!-- Concrete type -->
<xsd:complexType name="ElementTypeExtension">
<xsd:simpleContent>
<xsd:restriction base="abstr:ElementType">
<xsd:enumeration value="one"/>
<xsd:enumeration value="two"/>
<xsd:enumeration value="three"/>
</xsd:restriction>
</xsd:simpleContent>
</xsd:complexType>
<!-- Type that has a field of the abstract …Run Code Online (Sandbox Code Playgroud)