Chris Johnston

Web development and design with a little VFX thrown in for fun
  • Home
  • About Me
  • Contact Me
  • Projects
  • Resume

Any tips for writing mapping code?

Published by Chris Johnston on January 10, 2008 12:54 am under Application Development, Programming

Currently at work I am writing mapping code. Code that takes values from one anemic object model to another anemic object model to another anemic object model. Aside from the usual iteration code, most of the code is comprised of this.setSomething(other.getSomething());. Unfortunately, this code does not map one-to-one from one model to another.

Being new to this kind of coding, I am wondering if anyone has any tips, tricks, or patterns. We are trying to avoid having a large (1000+ line) class filled with procedural, linear code. So we have a bunch of utility, finder and builder methods and classes. This has made something better, but I am wondering if we could do more.

5 Comments so far

  1. Alexei Guevara on January 10th, 2008

    There is a Java Bean Mapping framework named Dozer, which has a fairly rich feature set. See the post about it in the TheServerSide. I haven’t used it personally, but it definitely looks very promising.

  2. Torbjörn Gyllebring on January 10th, 2008

    For the target you control, if any, you could probably use annotations to indicate what member to call to get the value I’ve done similar stuff in C# using attributes and it usually turns out quite elegant.

  3. Carfield Yim on January 10th, 2008

    Other than dozer, there are few libraries discussed at http://www.christianschenk.org/blog/java-bean-mapper-performance-tests/

  4. Christian Schenk on January 11th, 2008

    Thanks Yim, but I haven’t really discussed the libraries in detail, I’ve just looked at their performance.

    Anyway, I wrote some test code that might help you to try some things out; you can downlaod the Eclipse project as well.

    Cheers,
    Christian

  5. Chris Johnston on January 11th, 2008

    @Torbjörn – That would work, except we control no targets and are still using Java 1.4 so annotations are out (at least native Java ones) and the client is a long way away from letting us an annotations library.

    @Alexei & @Carfield – Thanks for the recommendations, I will have to check them out.

    The biggest problem with this mapping exercise is that we do not control any of the target domain models and one model uses all its own custom base object types (e.g., String, Decimal, Date, etc). Why any company would do this is beyond me.

Posting your comment.

  • Search

  • Categories

    • .NET (2)
    • Agile (41)
    • Apple Mac (15)
    • Application Development (124)
    • Articles (4)
    • ColdFusion (2)
    • Demo/Tutorial (3)
    • Eclipse (1)
    • Flash (6)
    • General (567)
    • Git (1)
    • Google (1)
    • Hibernate (4)
    • J2EE (39)
    • Java (111)
    • Java Frameworks (5)
    • Links (1)
    • Linux (33)
    • Miscellanous (2)
    • NetBeans (3)
    • News (10)
    • Open Source (6)
    • Photography (2)
    • Programming (33)
    • Python (1)
    • Ruby (27)
    • Ruby on Rails (14)
    • Ruby on Rails Web Apps (1)
    • Software (14)
    • Spring (4)
    • Teaching (1)
    • TeamDocs (6)
    • Technology (2)
    • Test Driven Development (1)
    • Thoughts (33)
    • ThoughtWorks (8)
    • Tips and Tricks (1)
    • User Experience (1)
    • Web Design (7)
    • Web Development (37)
    • Wicket (1)
  • Archives

    • September 2009 (1)
    • June 2009 (1)
    • May 2009 (1)
    • April 2009 (7)
    • March 2009 (2)
    • February 2009 (6)
    • January 2009 (4)
    • December 2008 (3)
    • October 2008 (1)
    • September 2008 (2)
    • August 2008 (6)
    • July 2008 (4)
    • June 2008 (1)
    • May 2008 (8)
    • April 2008 (7)
    • March 2008 (2)
    • February 2008 (1)
    • January 2008 (5)
    • December 2007 (3)
    • November 2007 (4)
    • October 2007 (5)
    • September 2007 (2)
    • August 2007 (3)
    • July 2007 (6)
    • June 2007 (5)
    • May 2007 (5)
    • April 2007 (5)
    • March 2007 (6)
    • February 2007 (9)
    • January 2007 (16)
    • December 2006 (6)
    • November 2006 (15)
    • October 2006 (17)
    • September 2006 (27)
    • August 2006 (22)
    • July 2006 (14)
    • June 2006 (10)
    • May 2006 (18)
    • April 2006 (3)
    • March 2006 (6)
    • February 2006 (15)
    • January 2006 (7)
    • December 2005 (11)
    • November 2005 (8)
    • October 2005 (18)
    • September 2005 (24)
    • August 2005 (18)
    • July 2005 (21)
    • June 2005 (14)
    • May 2005 (23)
    • April 2005 (18)
    • March 2005 (34)
    • February 2005 (27)
    • January 2005 (27)
    • December 2004 (15)
    • November 2004 (17)
    • October 2004 (20)
    • September 2004 (10)
    • August 2004 (21)
    • July 2004 (9)
    • June 2004 (11)
    • May 2004 (4)
    • April 2004 (15)
    • March 2004 (12)
    • February 2004 (7)
    • January 2004 (17)
    • December 2003 (11)
    • November 2003 (8)
    • October 2003 (12)
    • September 2003 (12)
    • August 2003 (12)
    • July 2003 (23)
    • June 2003 (22)
    • May 2003 (14)
    • April 2003 (9)
    • March 2003 (22)
    • February 2003 (24)
    • January 2003 (32)
    • December 2002 (11)
    • November 2002 (16)
    • October 2002 (10)
    • September 2002 (9)
    • August 2002 (13)
  • Pages

    • About Me
    • Contact Me
    • Projects
    • Resume

Copyright © 2010 Chris Johnston
WordPress Theme based on Light Theme