Serializable
Use xjc:serializable
in a custom bindings file to add the java.io.Serializable
interface to your classes along with a serialVersionUID
:
<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xsi:schemaLocation="
http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
version="2.1">
<globalBindings>
<serializable uid="1" />
</globalBindings>
</bindings>
toString()
Use a superclass (see xjc:superClass
) from which all your bound classes will inherit. This class won’t be generated by xjc so you are free to create it as you please (here with a toString()
implementation):
<?xml version="1.0" encoding="UTF-8"?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xsi:schemaLocation="
http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
version="2.1">
<globalBindings>
<serializable uid="1" />
<xjc:superClass name="the.package.to.my.XmlSuperClass" />
</globalBindings>
</bindings>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…