Convert XSD element choice with "maxOccurs=unbounded" into individual list of objects
Problem defined here:
http://archive.oreilly.com/pub/a/onjava/2003/12/10/jaxb.html?page=2
Plugins used:
https://github.com/highsource/jaxb2-basics/wiki/JAXB2-Simplify-Plugin
XSD Sample
<xs:schema xmlns:tns="http://www.omnicogroup.com/FPF/namespace" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.omnicogroup.com/FPF/namespace" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="transaction">
<xs:complexType>
<xs:sequence>
<xs:choice maxOccurs="unbounded">
<xs:element name="TransactionDetails">
<xs:complexType>
<xs:sequence>
<xs:choice >
<xs:element name="LogicalBusinessKey" type="xs:integer" />
<xs:element name="RecordName" type="xs:string" />
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
jaxb-bindings.xjb
<jxb:bindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema" jxb:version="2.1"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
xmlns:simplify="http://jaxb2-commons.dev.java.net/basic/simplify"
jxb:extensionBindingPrefixes="xjc simplify">
<jxb:bindings
node=".//xs:element[@name='transaction']/xs:complexType/xs:sequence/xs:choice">
<simplify:as-element-property/>
</jxb:bindings>
</jxb:bindings>
pom.xml
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.1</version>
<executions>
<execution>
<id>generate-sources-trans</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<generateDirectory>src/main/java</generateDirectory>
<generatePackage>com.disney.wdw.service.transaction.processing.xml.generated</generatePackage>
<schemaDirectory>src/main/resources</schemaDirectory>
<schemaIncludes>
<include>rtt.xsd</include>
</schemaIncludes>
<bindingDirectory>src/main/resources</bindingDirectory>
<bindingIncludes>
<bindingInclude>jaxb-bindings.xjb</bindingInclude>
</bindingIncludes>
</configuration>
</execution>
</executions>
<configuration>
<extension>true</extension>
<args>
<arg>-Xsimplify</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.11.0</version>
</plugin>
</plugins>
</configuration>
</plugin>
<dependencies>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.11.0</version>
</dependency>
</dependencies>
http://archive.oreilly.com/pub/a/onjava/2003/12/10/jaxb.html?page=2
Plugins used:
https://github.com/highsource/jaxb2-basics/wiki/JAXB2-Simplify-Plugin
XSD Sample
<xs:schema xmlns:tns="http://www.omnicogroup.com/FPF/namespace" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.omnicogroup.com/FPF/namespace" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="transaction">
<xs:complexType>
<xs:sequence>
<xs:choice maxOccurs="unbounded">
<xs:element name="TransactionDetails">
<xs:complexType>
<xs:sequence>
<xs:choice >
<xs:element name="LogicalBusinessKey" type="xs:integer" />
<xs:element name="RecordName" type="xs:string" />
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
jaxb-bindings.xjb
<jxb:bindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema" jxb:version="2.1"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:inheritance="http://jaxb2-commons.dev.java.net/basic/inheritance"
xmlns:simplify="http://jaxb2-commons.dev.java.net/basic/simplify"
jxb:extensionBindingPrefixes="xjc simplify">
<jxb:bindings
node=".//xs:element[@name='transaction']/xs:complexType/xs:sequence/xs:choice">
<simplify:as-element-property/>
</jxb:bindings>
</jxb:bindings>
pom.xml
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.1</version>
<executions>
<execution>
<id>generate-sources-trans</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<generateDirectory>src/main/java</generateDirectory>
<generatePackage>com.disney.wdw.service.transaction.processing.xml.generated</generatePackage>
<schemaDirectory>src/main/resources</schemaDirectory>
<schemaIncludes>
<include>rtt.xsd</include>
</schemaIncludes>
<bindingDirectory>src/main/resources</bindingDirectory>
<bindingIncludes>
<bindingInclude>jaxb-bindings.xjb</bindingInclude>
</bindingIncludes>
</configuration>
</execution>
</executions>
<configuration>
<extension>true</extension>
<args>
<arg>-Xsimplify</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.11.0</version>
</plugin>
</plugins>
</configuration>
</plugin>
<dependencies>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.11.0</version>
</dependency>
</dependencies>
Comments
Post a Comment