2

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?

lexicore
  • 42,748
  • 17
  • 132
  • 221
Alfredo A.
  • 1,697
  • 3
  • 30
  • 43

1 Answers1

1

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&lt;com.acme.foo.SomeClass&gt;</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.

lexicore
  • 42,748
  • 17
  • 132
  • 221
  • Perfect! How can I make it globally? Apply the inheritance to all the types defined in my xsd? – Alfredo A. Oct 09 '15 at 16:08
  • @AlfredoA. Just apply to many nodes via XPath. See http://stackoverflow.com/questions/12043255/jaxb-bindingx-xml-results-in-too-many-target-nodes – lexicore Oct 09 '15 at 16:44