Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a generic parameter to a class generated by JAXB?

I'm using maven-jaxb2-plugin and jaxb2-basics plugin to generate java classes from a XSD schema.

I need to make some of those generated classes implement a custom interface:

public interface MyInterface<O extends MyObject> {

    O getO();
    O setO(O myObject);

}

So I'm using the inheritance plugin, configured in a bindings file:

<jxb:bindings node="//xs:complexType[@name='MyXmlType']">
    <inheritance:implements>com.example.MyInterface</inheritance:implements>
</jxb:bindings> 

How can I specify the type of the generic parameter in the implementing class (MyXmlType)? Is there an already existing plugin?

like image 959
Virginie Avatar asked Sep 08 '25 08:09

Virginie


1 Answers

Actually it's pretty simple.

Just write the desired generic type in the binding.

<jxb:bindings node="//xs:complexType[@name='MyXmlType']">
    <inheritance:implements>com.example.MyInterface&lt;CustomMyObject&gt;</inheritance:implements>
</jxb:bindings>
like image 131
Sven Döring Avatar answered Sep 10 '25 02:09

Sven Döring