Schema compiler (XJC) produces schema-derived classes which can be used to turn XML into object structures and back. However, generated classes lack by default lack convenience and utility methods like
toString() and so on.
JAXB2 Basics provides a package of plugins which can generate such utility code
- Equals Plugin
- HashCode Plugin
- ToString Plugin
- Copyable Plugin
- Mergeable Plugin
- JAXBIndex Plugin
- Inheritance Plugin
- Wildcard Plugin
- AutoInheritance Plugin
- Setters Plugin
- Simplify Plugin
- EnumValue Plugin
Most utility methods generated by JAXB2 Basics plugins come in two flavours: default (like
equals(that) and with additional
strategy parameters (like
equals(thisLocator, thatLocator, that, strategy). This gives you a possibility to provide a custom strategy which will be used for object comparison, hash code calculation, content copying and so on.
When generating methods, plugins also make schema-derived classes implement corresponding interfaces from the runtime package. For instance, if you use the equals plugin, your classes will implement the Equals interface.
In order to access data from objects, generated code uses getters, setters and fields. For performance reasons, no reflection is used.
In some cases you may need to exclude certain properties from calculations in utility methods. You may use binding customizations to do this:
As you may guess,
basic:ignored marks the field to be ignored for all the plugins,
copyable:ignored - only for the copyable plugin.
Please check first the user guide for information on how to use JAXB2 plugins in your Ant builds.
Below is an example of XJC task configuration for JAXB2 Basics plugins:
Generated code depends on JAXB2 Basics runtime, so you'll need few further JARs in order to compile the code:
See the sample projects for a working example of an Ant project using JAXB2 Basics Plugins.
Please check first the user guide for information on how to use JAXB2 plugins in your Maven builds.
Below is an example of
maven-jaxb2-plugin configuration for JAXB2 Basics plugins:
Generated code depends on JAXB2 Basics runtime, so include the following dependency into your
See the sample projects for a working example of a Maven project using JAXB2 Basics Plugins.