Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 使用jaxb2 maven插件版本2.2生成Equals和HashCode_Xml_Maven_Jaxb_Maven Jaxb2 Plugin - Fatal编程技术网

Xml 使用jaxb2 maven插件版本2.2生成Equals和HashCode

Xml 使用jaxb2 maven插件版本2.2生成Equals和HashCode,xml,maven,jaxb,maven-jaxb2-plugin,Xml,Maven,Jaxb,Maven Jaxb2 Plugin,我们使用jaxb2 maven插件(版本2.2),并为每个JAXBO对象生成equal和hashCode方法。 我们已经读取了binding.xjb文件来配置任何东西 有没有办法生成这种方法 如果我尝试添加参数-Xequals-XhashCode,我会得到以下异常:unbekanner参数-Xequals-XhashCode 配置: <configuration> <arguments>-Xequals -XhashCode</arguments> </

我们使用jaxb2 maven插件(版本2.2),并为每个JAXBO对象生成equal和hashCode方法。 我们已经读取了binding.xjb文件来配置任何东西

有没有办法生成这种方法

如果我尝试添加参数-Xequals-XhashCode,我会得到以下异常:unbekanner参数-Xequals-XhashCode

配置:

<configuration> <arguments>-Xequals -XhashCode</arguments> </configuration>
-Xequals-XhashCode

谢谢大家!

您可以使用插件生成
hashCode
equals

我个人更喜欢生成“战略性”方法的
-Xequals
-XhashCode
。“策略”在某种意义上,这些方法使用传递的策略进行相等或哈希代码计算:

public boolean equals(Object object) {
    final EqualsStrategy2 strategy = JAXBEqualsStrategy.INSTANCE2;
    return equals(null, null, object, strategy);
}

public boolean equals(ObjectLocator thisLocator, ObjectLocator thatLocator, Object object, EqualsStrategy2 strategy) {
    if ((object == null)||(this.getClass()!= object.getClass())) {
        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, (this.shipTo!= null), (that.shipTo!= null))) {
            return false;
        }
    }
    // ...
    return true;
}

public int hashCode() {
    final HashCodeStrategy2 strategy = JAXBHashCodeStrategy.INSTANCE2;
    return this.hashCode(null, strategy);
}

public int hashCode(ObjectLocator locator, HashCodeStrategy2 strategy) {
    int currentHashCode = 1;
    {
        USAddress theShipTo;
        theShipTo = this.getShipTo();
        currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "shipTo", theShipTo), currentHashCode, theShipTo, (this.shipTo!= null));
    }
    // ...
    return currentHashCode;
}
策略方法非常酷,因为您可以自定义相等/哈希代码计算-例如,结构完全不同的日志。这是以运行时依赖性为代价的


免责声明:我是。

您可以使用插件生成
hashCode
equals

我个人更喜欢生成“战略性”方法的
-Xequals
-XhashCode
。“策略”在某种意义上,这些方法使用传递的策略进行相等或哈希代码计算:

public boolean equals(Object object) {
    final EqualsStrategy2 strategy = JAXBEqualsStrategy.INSTANCE2;
    return equals(null, null, object, strategy);
}

public boolean equals(ObjectLocator thisLocator, ObjectLocator thatLocator, Object object, EqualsStrategy2 strategy) {
    if ((object == null)||(this.getClass()!= object.getClass())) {
        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, (this.shipTo!= null), (that.shipTo!= null))) {
            return false;
        }
    }
    // ...
    return true;
}

public int hashCode() {
    final HashCodeStrategy2 strategy = JAXBHashCodeStrategy.INSTANCE2;
    return this.hashCode(null, strategy);
}

public int hashCode(ObjectLocator locator, HashCodeStrategy2 strategy) {
    int currentHashCode = 1;
    {
        USAddress theShipTo;
        theShipTo = this.getShipTo();
        currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "shipTo", theShipTo), currentHashCode, theShipTo, (this.shipTo!= null));
    }
    // ...
    return currentHashCode;
}
策略方法非常酷,因为您可以自定义相等/哈希代码计算-例如,结构完全不同的日志。这是以运行时依赖性为代价的


免责声明:我是该问题的作者。

此问题解决方案的可能副本是使用参数:-Xequals-XhashCode如果我尝试此操作,我会得到以下异常:unbekanner参数-Xequals-XhashCode我认为这两个问题之间的区别在于版本。可能在这个问题中,重复的解决方案是使用参数:-Xequals-XhashCode如果我尝试这个,我会得到以下异常:unbekanner参数-Xequals-XhashCode我认为这两个问题的区别在于版本。小更新:在版本1.11.1中,参数被重命名为
-Xequals-XhashCode
@petronius没有版本1.11.1-它是错误发布的。官方版本是0.11.1。@petronius也没有重命名参数。我不明白,maven repo 1.11.1确实存在:(以及1.11.1-错误发布)。为了使它工作,我必须编写
-Xequals
-XhashCode
,因为使用
-XsimpleEquals
我得到了错误:
[error]无法执行目标[…]执行org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.14.0:generate:java.lang.NoSuchMethodError:org.jvnet.jaxb2_commons.plugin.util.StrategyClassUtils.superClassNotIgnored(Lcom/sun/tools/xjc/outline/ClassOutline;Lorg/jvnet/jaxb2_commons/plugin/ignore;)Ljava/lang/Boolean使用maven-jaxb2-plugin 0.14.0.Small更新:在版本1.11.1中,参数被重命名为
-Xequals-XhashCode
@petronius没有版本1.11.1-它是错误发布的。官方版本是0.11.1。@petronius也没有重命名参数。我不明白,maven repo 1.11.1确实存在:(以及1.11.1-错误发布)。为了使它工作,我必须编写
-Xequals
-XhashCode
,因为使用
-XsimpleEquals
我得到了错误:
[error]无法执行目标[…]执行org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.14.0:generate:java.lang.NoSuchMethodError:org.jvnet.jaxb2_commons.plugin.util.StrategyClassUtils.superClassNotIgnored(Lcom/sun/tools/xjc/outline/ClassOutline;Lorg/jvnet/jaxb2_commons/plugin/ignore;)Ljava/lang/Boolean使用maven-jaxb2-plugin 0.14.0。
public boolean equals(Object object) {
    final EqualsStrategy2 strategy = JAXBEqualsStrategy.INSTANCE2;
    return equals(null, null, object, strategy);
}

public boolean equals(ObjectLocator thisLocator, ObjectLocator thatLocator, Object object, EqualsStrategy2 strategy) {
    if ((object == null)||(this.getClass()!= object.getClass())) {
        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, (this.shipTo!= null), (that.shipTo!= null))) {
            return false;
        }
    }
    // ...
    return true;
}

public int hashCode() {
    final HashCodeStrategy2 strategy = JAXBHashCodeStrategy.INSTANCE2;
    return this.hashCode(null, strategy);
}

public int hashCode(ObjectLocator locator, HashCodeStrategy2 strategy) {
    int currentHashCode = 1;
    {
        USAddress theShipTo;
        theShipTo = this.getShipTo();
        currentHashCode = strategy.hashCode(LocatorUtils.property(locator, "shipTo", theShipTo), currentHashCode, theShipTo, (this.shipTo!= null));
    }
    // ...
    return currentHashCode;
}