Thursday February 16, 2006
Bean to Bean Transformations
When it comes to transformation data from one format to another, XSLT in combination with XPath are handy tools. But what do you do, if you have an object graph of Java Beans, which cannot easily de-/serialized into XML? In this case Bean (or POJO)-based transformation can do the trick.
Serialization of object graphs to XML (as well as deserialization from XML to objects) may not as easy as one might guess. Arjen has posted a good summary about why some have started to rather use the term Object-XML Mapping (O/X Mapping or, even shorter OXM). Similar to Object-Relational Mappings (ORM), it there are tools like Castor and XML Beans, which can help if properly used. However, it will always be a problem to map complex object graph with cyclic references into XML.
So, what are bean-based tranformations? Until now, bean to bean transformations have mostly been used in web-scenarios, using tools like Jakarta Commons Beanutils or Springs BeanWrapper. However, as this requirements comes up in SOA/ESB environments with more complex object graphs new tools evolve. The following list displays the ones I came across recently:
- Dozer is described as “a powerful, yet simple Java Bean to Java Bean mapper that recursively copies data from one object to another.” The transformation are described in an XML file. From my first impression this tools looks promising.
- TopLink 10.1.3 (Oracle’s ORM tool) is support for object-to-XML mapping. Haven’t checked it out though.
- Jakarata Commons JXPath may be an oldie in this field, but using XPath on object graph is a really good idea and saves a lot of coding. I am currently using it and it work really great even on large object graphs.
- Opensource-ESB ServiceMix also provides support for other transformation technologies such as rule-based transformations (Drools) and scripting support (like Groovy).
So, if you only need to transform data from ony object graph to another, these tools avoid the need to convert beans to XML and fight with the complications of OXM. In the future we might see tools like Dozer being extended with JXPath support or the like to allow more powerful mappings. Also a transformation builder would be really helpful.
Update: Another Tool is https://otom.dev.java.net which does include a transformation design tool.
Update 2: As Franz pointed out, the Dozer team is also developing an Eclipse plugin. In the SF.net forums is a post how to get a preview.
Posted on Feb 16, 2006 at 20:43 (MET) | Permalink | 4 comments