'XSD with restrictions and code generation
I have many xsd files in the project and I am generaing classes sucessfully but I would also like to use generated classes to fill my runtime dictionary, how to do that ?
So in below xsd part there is restriction, that for example code can have A value.
<xs:complexContent>
<xs:restriction base="xx-code:Code">
<xs:sequence>
<xs:element name="code" form="unqualified">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:enumeration value="A">
<xs:annotation>
<xs:appinfo>
<Test>Test A</Test>
</xs:appinfo>
</xs:annotation>
</xs:enumeration>
After class generation it is only visible as javadoc of generated class:
<restriction base="{http://www.w3.org/2001/XMLSchema}token">
* <enumeration value="A"/>
* <enumeration value="B"/>
I would like to have some enum generated so that I would use it to expose REST service for frontend application to tell what values are valid (to populate drowndown lists)
I am using this plugin for code generation:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>${jaxb2-maven-plugin.version}</version>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<sources>
<source>src/main/resources/my.xsd</source>
</sources>
<outputDirectory>${basedir}/target/generated-sources/java</outputDirectory>
<clearOutputDir>false</clearOutputDir>
</configuration>
</plugin>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
