Skip to content

JAXB2 HashCode Plugin

Laurent Schoelens edited this page Nov 13, 2023 · 2 revisions

HashCode plugin

HashCode plugin generates hashCode(...) methods:

public class PurchaseOrderType
    implements HashCode //, ...

    // ...    
    public int hashCode() {
        final HashCodeStrategy strategy = JAXBHashCodeStrategy.INSTANCE;
        return this.hashCode(null, strategy);
    }


    public int hashCode(ObjectLocator locator, HashCodeStrategy strategy) {
        int currentHashCode = 1;
        {
            USAddress theShipTo;
            theShipTo = this.getShipTo();
            currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "shipTo", theShipTo), currentHashCode, theShipTo);
        }
        {
            USAddress theBillTo;
            theBillTo = this.getBillTo();
            currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "billTo", theBillTo), currentHashCode, theBillTo);
        }
        // ...
        return currentHashCode;
    }
    // ...
}

Generated methods allow you to specify a custom hash code strategy (hash code strategy).

Activation

Use the -XhashCode argument to activate the plugin.

Configuration

By default, generated code uses :

  • org.jvnet.jaxb2_commons.lang.JAXBHashCodeStrategy as hash code strategy for JAXB2 (javax namespace) version.
  • org.jvnet.jaxb.lang.JAXBHashCodeStrategy as hash code strategy for JAXB3+ (jakarta namespace) version.

You can specify class name of your custom strategy using the -XhashCode-hashCodeStrategyClass argument:

-XhashCode-hashCodeStrategyClass=com.acme.foo.CustomHashCodeStrategy

Clone this wiki locally