I tried the solution of the question here JAXB Simplify plugin vs *.xjb.
but it failed with the following exception
" compiler was unable to honor this simplify:as-element-property customization. It is attached to a wrong place, or its inconsistent with other bindings. "
this is customization binding I used
<jaxb:bindings node="//xs:complexType[@name='Op']//xs:choice/xs:element[@name='Time']">
<simplify:as-element-property/>
</jaxb:bindings>
the jaxb simplify plugin confluence page is not accessible, so has anyone used this plugin and can give an example please?
Here is my updated schema according to the answer
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified" xmlns="http://www.amadeus.com/APT/FOM/00" targetNamespace="http://www.amadeus.com/APT/FOM/00" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:simplify="http://jaxb2-commons.dev.java.net/basic/simplify" jaxb:extensionBindingPrefixes="simplify">
...
...
<xs:complexType>
<xs:sequence>
<xs:choice minOccurs="1" maxOccurs="1">
<xs:element name="Time" type="xs:dateTime" minOccurs="1" maxOccurs="1">
<xs:annotation>
<xs:appinfo>
<simplify:as-element-property />
</xs:appinfo>
</xs:annotation>
</xs:element>
... ...
</xs:choice>
...
I got the exception during the maven build like "Unsupported binding namespace "http://jaxb2-commons.dev.java.net/basic/simplify". Perhaps you meant "http://jaxb.dev.java.net/plugin/code-injector"?"
Disclaimer: I am the author of the Simplify plugin which is the part of JAXB2 Basics.
The plugin an the project is well and alive, but my documentation server dies from time to time. I have no resources to maintain an own hosting so I'm moving all my projects to GitHub.
You can find the JAXB2 Basics project here:
https://github.com/highsource/jaxb2-basics
Documentation is not moved yet, but here's a link to one of test projects which use it:
https://github.com/highsource/jaxb2-basics/tree/master/tests/issues
Below is a fragment of the schema which uses simplify:as-element-property
customization:
<xs:complexType name="gh1" mixed="true">
<xs:sequence>
<xs:element name="a" type="xs:string">
<xs:annotation>
<xs:appinfo>
<simplify:as-element-property/>
</xs:appinfo>
</xs:annotation>
</xs:element>
<xs:element name="b" type="xs:int"/>
</xs:sequence>
</xs:complexType>
I'll bring the server back online in few hours.
Please post your schema/customization for us to check. The problem you have is probably that you have put the customization in the wrong place. This is sometimes hard to figure out.
Update
This error:
"Unsupported binding namespace "http://jaxb2-commons.dev.java.net/basic/simplify". Perhaps you meant "http://jaxb.dev.java.net/plugin/code-injector"?"
Means that the plugin is missing or not activated. I assume you use maven-jaxb2-plugin
. Then make sure you have jaxb2-basics
as JAXB2 plugin and also included the -Xsimplify
switch. Here's a sample:
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<configuration>
<extension>true</extension>
<args>
<arg>-Xsimplify</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
</plugin>
</plugins>
</configuration>
</plugin>
Next, your original error "unable to honor this ... customization" may be related to WHERE you place te customization. You have placed it on the element (which is what I'd do also).
But in some cases XJC reads these customizations from other schema components. In your case, try to place the customization on xs:choice
instead.
If the error persists, please file an issue on GitHub providing the minimal schema which reproduces the error. I'll take care of it then.
Update 2
The server is back online, but I have now moved the documentation of the JAXB2 Simplify Plugin to the GitHub:
https://github.com/highsource/jaxb2-basics/wiki/JAXB2-Simplify-Plugin
Update 3
The final solution with version 0.9.1 is sketched here:
https://github.com/highsource/jaxb2-basics/issues/3
Customize the class with:
<simplify:property name="type2OrType3">
<simplify:as-element-property/>
</simplify:property>
Example.