GWT and JAXB Basics Runtime

919 views Asked by At

I am using CXF JAXB generated classes in a GWT application. I would like equals() and hashCode() to be added to the generated classes. I have successfully used the JAXB2 Basics Plugins (http://confluence.highsource.org/display/J2B/JAXB2+Basics+Plugins) and the JAXB2 Basics Runtime with CXF in the maven POM to generate them. However, the generated classes are now incompatible with GWT. The classes have dependencies which are not emulated by GWT, e.g., java.util.ResourceBundle, java.net.URL.

I am considering using a CustomEqualsStrategy but that will still leave the org.jvnet.jaxb2_commons.locator.ObjectLocator class. Has anyone got this to work?

1

There are 1 answers

0
lexicore On BEST ANSWER

This question has an answer now.

I have collaborated with James (the OP, @ja6a) and together we have developed the JAXB2 SimpleEquals Plugin and JAXB2 SimpleHashCode Plugin which generate runtime-free reflection-free equals(...) and hashCode() methods. As there's no additional runtime dependencies, this is compatible with GWT.

Examples of the generated code:

Usage:

Below is a snippet from a sample pom.xml:

        <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <configuration>
                <extension>true</extension>
                <args>
                    <arg>-XsimpleEquals</arg>
                    <arg>-XsimpleHashCode</arg>
                </args>
                <plugins>
                    <plugin>
                        <groupId>org.jvnet.jaxb2_commons</groupId>
                        <artifactId>jaxb2-basics</artifactId>
                    </plugin>
                </plugins>
            </configuration>
        </plugin>

As mentioned above, no runtime required.

These plugins handle a huge number of cases and corner cases and corners of corners cases. For instance, we had to implement special handling for things like JAXBElements and arrays as they don't implement hashCode() and equals(...) methods. The plugins also handle primitive types.

Many thanks for James Annesley for his help.