I am using maven-jaxb2-plugin to create java classes from xsd. In xsd I have defined two status: Status1 and Status2. This two classes has a lot of similar variables. Because I cant edit xsd is there a option to create class Status in my project and then add change generated class to extend this class?
Example
now:
Class Status1 {...}
Class Status2 {...}
What I want:
Class Status1 extends Status {...}
Class Status2 extends Status {...}
Class Status {...}
- my own class
I hope this can be done by bindings but I dont know how
UPDATE:
second option how to achieve this question is to add to class Status1 new variable. Is this possible ?
What I want:
Class Status1 {... NewVariable newVariable ...}
Class Status2 {...}
ok I found it: I use extend:
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
jaxb:version="2.1" xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
jaxb:extensionBindingPrefixes="inheritance">
<jaxb:bindings schemaLocation="mySchema.xsd">
<jaxb:bindings node="xsd:complexType[@name='StatusType']">
<inheritance:extends>my.package.Status1</inheritance:extends>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
and in JAXB2 plugin I need to add:
<extension>true</extension>
<args>
<arg>-Xinheritance</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.4</version>
</plugin>
</plugins>
For the first part of the question see Specifying Super Class of a JAXB-Generated Class .
For the second part see Generate additional custom method with jaxb-xjc . It's about adding custom methods. But custom fields handling should be similar.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.