JAXB Simplify plugin still usable?

核能气质少年 提交于 2019-12-04 05:26:40

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!