How to generate equals () and hashcode () methods using wsimport in jaxws

The generated classes from my WSDL using wsimport do not have equals() and hashcode() methods. How to configure and generate client classes to get equals() and hashcode() methods.

I am not sure about using JAXB for this.

In Axis2.0, the generated stubs are generated by these methods, but are not sure why such a basic thing is not available in JAXWS!

+6
source share
3 answers

You can use the JAXB2 Basics plugin to generate the equals() and hashcode() methods:

+6
source

Learn more about how this works. I have to add a classpath to jaxb2-commons and without which wsimport works without complaints, but nothing happens! After adding the classpath below

 <path id="jaxb2-commons.classpath"> <fileset dir="${dir.toolchain}/noarch/jaxb2-basics-dist-0.6.0"> <include name="**/*.jar" /> </fileset> </path> 

below wsimport worked as expected

 <wsimport wsdl="@{dir-wsdl}/@{name-wsdl}" taskname=" wsimport-@ {service}" destdir="@{dest-dir}" sourcedestdir="@{source-dest-dir}" package="@{package}" keep="@{keep}" verbose="@{verbose}" xdebug="@{xdebug}" xnocompile="@{xnocompile}" target="2.1"> <binding dir="@{dir-wsdl}" includes=" bindings-wsdl-@ {name-wsdl}.xml, bindings-schema-@ {name-wsdl}.xml" /> <xjcArg value="-Xequals" /> <xjcArg value="-XhashCode" /> <xjcArg value="-XtoString" /> <!-- Generates per-package jaxb.index file which lists all of the schema-derived classes in this package.--> <xjcArg value="-Xjaxbindex" /> <xjcArg value="-Xsetters" /> </wsimport> 
+1
source

If you want to generate hashcode () and equals () using wsimport in maven, check out this answer on how to create value constructors, but also includes a configuration for generating hashcode () and equals () too:

How to create wsimport generation constructors?

+1
source

Source: https://habr.com/ru/post/891653/


All Articles