Skip to end of metadata
Go to start of metadata

Introduction

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 equals(...), hashCode(...), toString() and so on.

JAXB2 Basics provides a package of plugins which can generate such utility code

Plugins

Custom strategues

Most utility methods generated by JAXB2 Basics plugins come in two flavours: default (like equals(that) and with additional locator and 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.

Implemented interfaces

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.

No Reflection

In order to access data from objects, generated code uses getters, setters and fields. For performance reasons, no reflection is used.

Excluding properties

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.

Ant usage

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.

Maven usage

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 project/dependencies section:

See the sample projects for a working example of a Maven project using JAXB2 Basics Plugins.

  • No labels