6.6. Obtaining Jakarta Commons Betwixt

Problem

You need to use Jakarta Commons Betwixt to serialize and deserialize beans to and from XML documents.

Solution

You must download the latest version of Commons Betwixt, and place the Commons Betwixt JAR in your project’s classpath. Following the steps outlined in Recipe 1.1, download Commons Betwixt 0.5 instead of Commons Lang. Uncompress the distribution archive and place commons-betwixt.jar in your classpath. Commons Betwixt depends on Commons Digester, Commons BeanUtils, Commons Logging, and Commons Collections. To download dependencies, see Recipe 3.2, Recipe 5.1, Recipe 6.1, and Recipe 7.9.

Discussion

Betwixt allows you to translate from beans to XML and vice versa. Beans are serialized to XML documents using a BeanWriter, and they are read from XML using a BeanReader. The structure of the XML can be automatically generated or customized using an XML document to bind properties to elements or attributes.

If you have a Maven project that needs to use Commons Betwixt, add a dependency on Commons Betwixt 0.5 with the following section in project.xml:

<dependencies>
  <dependency>
    <id>commons-betwixt</id>
    <version>0.5</version>
  </dependency>
  ....other dependencies...
</dependencies>

See Also

For more information about Commons Betwixt, see the Commons Betwixt project page at http://jakarta.apache.org/commons/betwixt.

Get Jakarta Commons Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.