That never faced having to write 10 lines of code just to copy the variables from one object to another?
Classic example of a MVC framework: You get the form submitted as Bean. You must then pass all values to the object representing the model (model.setNom (bean.getNom ()), model.setAge (bean.getAge ()) ....).
This happens even when you have five values to enter, but with forms containing 20 fields and that's another story ...
To simplify all this, there is a small framework that requires only one line of code: Dozer
MapperIF mapper = new DozerBeanMapper();
DestinationObject destObject = (DestinationObject) mapper.map(sourceObject, DestinationObject.class);
That's it. This requires however that the attributes of the two objects have the same name. Otherwise we must add an XML file to describe the various fields to map:
<mapping>
<class-a>package.SourceClassName</class-a>
<class-b>package.DestinationClassName</class-b>
<field>
<A>SourceFieldName</A>
<B>DestinationFieldName</B>
</field>
</mapping>
In this example: the attribute of the object SourceFieldName SourceClassName will be copied to the attribute of the object DestinationFieldName DestinationFieldName. It is also possible to specify the attributes to be excluded when copying.
In short, this is a very useful tool to offload tedious sometimes inserting the values of a Bean to another object.


