I have an hyperjaxb xsd file and binding configuration. How can I force my generated classes to implement a custom interface declared in another artifact? I know I can make them extend another class by using
<xjc:superClass name="com.sample.jpa.entities.BaseEntity"/>
But I need them to implement another interface also. How can I achieve that?
Disclaimer: Author of Hyperjaxb and JAXB2-Basics here.
You can use the Inheritance plugin from JAXB2-Basics together with Hyperjaxb. You can both extend a class or implement an interface. The plugin can also process generics so you can even do stuff like <inheritance:implements>com.acme.foo.MyInterface<com.acme.foo.SomeClass></inheritance:implements>
.
Short guide:
Enable th plugin via <arg>-Xinheritance</arg>
in your pom.xml
. Something like:
<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 is a dependency if Hyperjaxb so you most probably won't need to do anything else here. See the example (for the annotate plugin but that does not matter).
Customize your complex types with inheritance:extends
or inheritance:implements
customization elements. Example:
<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>
That should be it.