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?
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(...)
andhashCode()
methods. As there's no additional runtime dependencies, this is compatible with GWT.Examples of the generated code:
equals(...)
hashCode()
Usage:
-XsimpleEquals
and-XsimpleHashCode
switchesBelow is a snippet from a sample
pom.xml
: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
JAXBElement
s and arrays as they don't implementhashCode()
andequals(...)
methods. The plugins also handle primitive types.Many thanks for James Annesley for his help.