Serializing Groovy Beans to XML

In this recipe, we are going to learn how to serialize a Groovy Bean into XML and back. Groovy Beans are discussed in detail in the Writing less verbose Java Beans with Groovy Beans recipe from Chapter 3, Using Groovy Language Features. The steps from this recipe can be applied either to POJO or POGO.

Getting ready

Groovy doesn't have a default XML object serializer. The groovy.xml.MarkupBuilder is an excellent tool for generating XML in a fluent way but doesn't offer any simple mechanism to create an XML document out of bean properties.

There is, on the other hand, a large offer of third-party Java libraries for XML serialization. In this recipe, we are going to look at XStream (http://xstream.codehaus.org/). XStream ...

Get Groovy 2 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.