Bean to Bean Transformations

Filed under: Java, Engineering

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.

Feb 16, 2006 at 20:43 | Permalink

4 Comments

  • 1. Franz Garsombke  |  February 17th, 2006 at 7:30 am

    The Java community does seem to be lacking some good bean mapping tools. I was amazed on my last project to find a dozen xml-to-java tools but no true java bean-to-java bean tools. There are other options like mapping XSD to beans if you are using Web Services…but if you need a rich feature set (inheritance mapping, conversion, etc.) it might be easier to just map the marshalled java objects to your domain objects.

    Dozer does have an initiative to create an eclipse plugin for transformations. I think this would be a huge advantage. I just don’t know how much time we can spend on it.

    Thanks for your support.

    Franz

  • 2. Stefan Kleineikenscheidt &hellip  |  March 7th, 2006 at 12:27 am

    […] t of webMethods services in my favourite taglib Displaytag as well as a range of other for data mapping, such as JXPath. Mar 6, 2006 […]

  • 3. Ehrann  |  April 3rd, 2008 at 4:28 pm

    So, any change since more than 2 years ago?
    Dozer still doesn’t have a plug-in…
    OTOM is not quite there yet…
    And we still tailor VO / DTOs and Webservice Beans manually…

    Maybe we do something wrong? maybe no one really needs this type of mapping? or did we realize that without manual mapping, we will have very little stuff to do at work? ;)

    Isn’t there a simple code generator for eclipse that generates an adapter that maps 2 types?

    Someone must have already started writing one. I hate to waste my time writing it and finding out I didn’t search google for the right term ;)

  • 4. Object conversion dozer(e&hellip  |  November 24th, 2008 at 7:14 pm

    […] 24, 2008 · No Comments Continuing on my experiences on the object mapping exercises, I found a interesting site here ,which eulogize it saying it is currently the most powerful bean-2-bean mapping utilities found on the net. Others being Apache Commons Beanutils and Spring BeanWrapper. I dont deny that Dozer is the most powerful bean mapping utility compared to others, but for simple and straightforward examples.  […]

Leave a Comment

(Required, Why?)

(Required)

(Optional)

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed