-
Notifications
You must be signed in to change notification settings - Fork 54
JAXB2 ToString Plugin
maffe edited this page Sep 3, 2019
·
2 revisions
Adds reflection-free strategy-based toString(...)
methods to the schema-derived classes.
Generated classes will implement the org.jvnet.jaxb2_commons.lang.ToString2
interface which, in addition to toString
declares append
and appendFields
methods. Below is an example:
public class SequenceType implements ToString2
{
// ...
public String toString() {
final ToStringStrategy2 strategy = JAXBToStringStrategy.INSTANCE;
final StringBuilder buffer = new StringBuilder();
append(null, buffer, strategy);
return buffer.toString();
}
public StringBuilder append(ObjectLocator locator, StringBuilder buffer, ToStringStrategy2 strategy) {
strategy.appendStart(locator, this, buffer);
appendFields(locator, buffer, strategy);
strategy.appendEnd(locator, this, buffer);
return buffer;
}
public StringBuilder appendFields(ObjectLocator locator, StringBuilder buffer, ToStringStrategy2 strategy) {
{
String theA;
theA = this.getA();
strategy.appendField(locator, this, "a", buffer, theA, this.isSetA());
}
{
Long theB;
theB = this.getB();
strategy.appendField(locator, this, "b", buffer, theB, this.isSetB());
}
return buffer;
}
}
- Activate the plugin using the
-XtoString
switch. -
Optionally provide custom strategy class using
-XtoString-toStringStrategyClass=com.acme.foo.MyToStringStrategy
(org.jvnet.jaxb2_commons.lang.JAXBToStringStrategy
is used by default).
-
JAXB2 Basics Plugins
- Using JAXB2 Basics Plugins
- JSR-305 Support
- SimpleEquals Plugin
- SimpleHashCode Plugin
- Equals Plugin
- HashCode Plugin
- ToString Plugin
- Copyable Plugin
- Mergeable Plugin
- Inheritance Plugin
- AutoInheritance Plugin
- Wildcard Plugin
- Setters Plugin
- Simplify Plugin
- EnumValue Plugin
- JAXBIndex Plugin
- FixJAXB1058 Plugin
- Sample Projects