Menu

Home

Sachin

Omapper is a simple library which provides utilities to transform java beans from one design layer to another. Say for example , you have a legacy application which has some java beans like Customer, Account etc. And while adding another access layer like web services, it would again have some bean with same structure and data as the backend application. So , as a result we have two similar classes. Now , while communicating between different layers , we write a error prone transformation logic which comprises of multiple chained get and set operations. For Example: There is a business layer which has a bean called Bean1:

public class Bean1 {

/** The name. */
private String name;

/** The address. */
private String address;

/** The age. */
private int age;

/** The emp_id. */
private Integer emp_id;
}

And similarly web service layer above that also exposes a bean called Bean2 with exactly same structure as BS one:

public class Bean2 {

/** The name. */
private String name;

/** The address. */
private String address;

/** The age. */
private int age;

/** The emp_id. */
private Integer emp_id;        
}

Earlier you would write some transformation method like :

transformBean1ToBean2(Bean1 bean1, Bean2 bean2)
{ 
    bean2.setAddress(bean1.getAddress());
    bean2.setAge(bean1.getAge());
    bean2.setEmp_id(bean1.getEmp_id());
    bean2.setName(bean1.getName());
}

So, this approach has a few drawbacks:

=> As the number of properties increase the get-set clutter increase and sometimes leads to missing mappings.

=> Anytime a new property is added or removed both bean definition and transformation logic needs to revisited.

=> Matters get worse when the names of the properties in the two bean classes have different names but same information, the get-set code gets more error prone.

=> What if the target bean needs to collate information from more than one bean? The get-set block tends to be a bit messed up.


Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.