I am using ant wsimport to generate client stub from the wsdls. Also, I would like to generate client classes that implements Serializable
. I would like to generate a different serialVersionUID
for each class. I tried with the binding file that was shown below. But its generating same serialVersionUID
for all the classes. Is there any way I can give my own serialVersionUID
to each class?
<wsimport xendorsed="true" binding="binding.xml" debug="true" keep="true"
verbose="false" sourcedestdir="${generated}" wsdl="${src}${wsdl.file}"
wsdlLocation="${wsdl.file}">
</wsimport>
binding configuration
<bindings xmlns="http://java.sun.com/xml/ns/jaxb" version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<globalBindings>
<serializable uid="1" />
</globalBindings>
</bindings>
Just for the record, there is no way to generate a unique serialVersionUID
for each generated class because it doesn't make sense to do so.
Let me explain :
A serialVersionUID
represents a version of your class at a particular point in time. If you modify your class, your serialVersionUID
should change.
So when the JDK deserialize objects of the same class, it knows to which version of your class to deserialize it to.
In the case of JAXB, since you generate all your classes at once every time it doesn't make sense to version all the classes individually. Simply because they can only change as a group. (Unless you take them out of your target folder..)
I hope that makes a little bit more sense.
This is the binding file we use, which does the trick for us.
<xs:schema elementFormDefault="qualified" version="1.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" jaxb:version="2.0"
jaxb:extensionBindingPrefixes="xjc">
<xs:annotation>
<xs:appinfo>
<jaxb:globalBindings>
<xjc:serializable />
</jaxb:globalBindings>
</xs:appinfo>
</xs:annotation>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With