Skip to content

JAXB2 Equals Plugin

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

Equals plugin

Equals plugin generates equals(...) methods:

public class PurchaseOrderType
    implements Equals //, ...
 
    // ...   
 
    public boolean equals(Object object) {
        final EqualsStrategy strategy = JAXBEqualsStrategy.INSTANCE;
        return equals(null, null, object, strategy);
    }
 
    public boolean equals(ObjectLocator thisLocator, ObjectLocator thatLocator, Object object, EqualsStrategy strategy) {
        if (!(object instanceof PurchaseOrderType)) {
            return false;
        }
        if (this == object) {
            return true;
        }
        final PurchaseOrderType that = ((PurchaseOrderType) object);
        {
            USAddress lhsShipTo;
            lhsShipTo = this.getShipTo();
            USAddress rhsShipTo;
            rhsShipTo = that.getShipTo();
            if (!strategy.equals(LocatorUtils.property(thisLocator, "shipTo", lhsShipTo), LocatorUtils.property(thatLocator, "shipTo", rhsShipTo), lhsShipTo, rhsShipTo)) {
                return false;
            }
        }
        {
            USAddress lhsBillTo;
            lhsBillTo = this.getBillTo();
            USAddress rhsBillTo;
            rhsBillTo = that.getBillTo();
            if (!strategy.equals(LocatorUtils.property(thisLocator, "billTo", lhsBillTo), LocatorUtils.property(thatLocator, "billTo", rhsBillTo), lhsBillTo, rhsBillTo)) {
                return false;
            }
        }
        // ...
        return true;
    }
 
    // ...
}

Generated methods allow you to specify a custom equality strategy (equals strategy).

This plugin needs JAXB2 Basics Runtime dependency.

Activation

Use -Xequals argument to activate the plugin.

Configuration

By default, generated code uses :

  • org.jvnet.jaxb2_commons.lang.JAXBEqualsStrategy as equals strategy for JAXB2 version (javax namespace).
  • org.jvnet.jaxb.lang.JAXBEqualsStrategy as equals strategy for JAXB3+ version (jakarta namespace).

You can specify class name of your custom strategy using the -Xequals-equalsStrategyClass argument:

-Xequals-equalsStrategyClass=com.acme.foo.CustomEqualsStrategy

Clone this wiki locally