设置hyperjaxb映射强制实现外部接口
Setting hyperjaxb mapping to force implementation of external interface
我有一个 hyperjaxb xsd 文件和绑定配置。我如何强制生成的 classes 实现在另一个工件中声明的自定义接口?我知道我可以使用
让他们扩展另一个 class
<xjc:superClass name="com.sample.jpa.entities.BaseEntity"/>
但我还需要它们实现另一个接口。我怎样才能做到这一点?
免责声明: Hyperjaxb and JAXB2-Basics 的作者在这里。
可以使用Inheritance plugin from JAXB2-Basics together with Hyperjaxb。您既可以扩展 class 也可以实现接口。该插件还可以处理泛型,因此您甚至可以执行 <inheritance:implements>com.acme.foo.MyInterface<com.acme.foo.SomeClass></inheritance:implements>
.
之类的操作
简短指南:
通过 pom.xml
中的 <arg>-Xinheritance</arg>
启用插件。类似于:
<plugin>
<groupId>org.jvnet.hyperjaxb3</groupId>
<artifactId>maven-hyperjaxb3-plugin</artifactId>
<configuration>
<!--result>mappingFiles</result-->
<roundtripTestClassName>org.jvnet.hyperjaxb3.ejb.tests.cuone.RoundtripTest</roundtripTestClassName>
<args>
<arg>-Xinheritance</arg>
</args>
</configuration>
</plugin>
JAXB2-Basics 是 Hyperjaxb 的依赖项,因此您很可能不需要在此处执行任何其他操作。请参阅 example(对于注释插件,但这并不重要)。
使用 inheritance:extends
或 inheritance:implements
自定义元素自定义您的复杂类型。示例:
<jaxb:bindings schemaLocation="schema.xsd" node="/xsd:schema">
<jaxb:bindings node="xsd:complexType[@name='WillBeMadeCloneableType']">
<inheritance:implements>java.lang.Cloneable</inheritance:implements>
</jaxb:bindings>
</jaxb:bindings>
应该是这样。
我有一个 hyperjaxb xsd 文件和绑定配置。我如何强制生成的 classes 实现在另一个工件中声明的自定义接口?我知道我可以使用
让他们扩展另一个 class <xjc:superClass name="com.sample.jpa.entities.BaseEntity"/>
但我还需要它们实现另一个接口。我怎样才能做到这一点?
免责声明: Hyperjaxb and JAXB2-Basics 的作者在这里。
可以使用Inheritance plugin from JAXB2-Basics together with Hyperjaxb。您既可以扩展 class 也可以实现接口。该插件还可以处理泛型,因此您甚至可以执行 <inheritance:implements>com.acme.foo.MyInterface<com.acme.foo.SomeClass></inheritance:implements>
.
简短指南:
通过
pom.xml
中的<arg>-Xinheritance</arg>
启用插件。类似于:<plugin> <groupId>org.jvnet.hyperjaxb3</groupId> <artifactId>maven-hyperjaxb3-plugin</artifactId> <configuration> <!--result>mappingFiles</result--> <roundtripTestClassName>org.jvnet.hyperjaxb3.ejb.tests.cuone.RoundtripTest</roundtripTestClassName> <args> <arg>-Xinheritance</arg> </args> </configuration> </plugin>
JAXB2-Basics 是 Hyperjaxb 的依赖项,因此您很可能不需要在此处执行任何其他操作。请参阅 example(对于注释插件,但这并不重要)。
使用
inheritance:extends
或inheritance:implements
自定义元素自定义您的复杂类型。示例:<jaxb:bindings schemaLocation="schema.xsd" node="/xsd:schema"> <jaxb:bindings node="xsd:complexType[@name='WillBeMadeCloneableType']"> <inheritance:implements>java.lang.Cloneable</inheritance:implements> </jaxb:bindings> </jaxb:bindings>
应该是这样。