为什么JAXB继承在静态类中不起作用

时间:2018-08-20 13:05:55

标签: java binding jaxb

我有xsd:

<xs:complexType name="AppService1ResponseType">
    <xs:complexContent>
        <xs:extension base="AppResponseType">
            <xs:sequence minOccurs="0">
                <xs:element name="Person" minOccurs="0" maxOccurs="unbounded">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="Element1" type="xs:string" nillable="true"
                                minOccurs="0" /> ....

AppService1ResponseType内生成静态类

public static class Osoba
    implements Serializable

binding.xml

    <jaxb:bindings node="//xs:complexType[@name='AppService1ResponseType']/xs:complexContent/xs:extension/xs:sequence/xs:element[@name='Person']">
        <inheritance:implements>com.app.PersonI</inheritance:implements>
    </jaxb:bindings>

应实现与此生成类的接口。我也尝试了另一个XPath或只是element[@name='Person'],但没有成功。当我尝试另一个非静态类(例如AppService1ResponseType)时,继承工作正常。有一些解决方法如何解决此问题?

1 个答案:

答案 0 :(得分:1)

好。我发现xpath中出现错误,错误应以/xs:complexType

结尾

因此绑定中正确的xpath是:

<jaxb:bindings node="//xs:complexType[@name='AppService1ResponseType']/xs:complexContent/xs:extension/xs:sequence/xs:element[@name='Person']/xs:complexType">
    <inheritance:implements>com.app.PersonI</inheritance:implements>
</jaxb:bindings>