Central point of software development is to handle data aggregation, data separation, data transformation and so on. For example let's have a look at ESB (Enterprise Service Bus) software systems. The main aspect of ESBs is the orchestration of data from different endpoints. Often developers map directly objects via getter and setter methods. Another way is to use an automatic Java object mapping framework how Dozer. Dozer use a XML file, which contains attribute mapping instructions. Dozer object mapping based on Java bean specification. If Java attributes have the same name, they will be mapped by Dozer directly. If not, you have to extend the Dozer XMl file. For instance Dozer is used in Apache Camel project for transformation of data transfer objects.
1. Database object CustomerDBO:
@Entity
public class CustomerDBO {
@Id
private Long id;
public void setId(Long id) {
this.id = id;
}
public Long getId() {
return this.id;
}
private String foreName;
public void setForeName(String foreName) {
this.forName = forName;
}
public String getForeName() {
return this.forName;
}
private String sureName;
public void setSureName(String sureName) {
this.sureName = sureName;
}
public String getSureName() {
return this.sureName;
}
private String sex;
public void setSex(String sex) {
this.sex = sex;
}
public String getSex() {
return this.sex;
}
}
2. Database Access object CustomerDBO:
public class CustomerDAO {
private Long id;
public void setId(Long id) {
this.id = id;
}
public Long getId() {
return this.id;
}
private String firstName;
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getFirstName() {
return this.firstName;
}
private String lastName;
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getLastName() {
return this.lastName;
}
private String gender;
public void setGender(String gender) {
this.gender = gender;
}
public String getGender() {
return this.gender;
}
}
3. Dozer mapping definition file dozer-bean-mappings.xml (bi-directional):
4. Spring Integrationorg.developers.blog.dbo.CustomerDBO org.developers.blog.dbo.CustomerDTO foreName firstName sureName lastName sex gender
5. Usage
dozer-bean-mappings.xml
//get dbo object from persistence unit and map with Dozer CustomerDAO dao = mapper.map(dbo, CustomerDAO.class);Regards
Rafael Sobek
Technorati Tags: Dozer Java Object Mapping

We tried dozer before in one of our projects, around 3 years ago. We tried it among other object-to-object mappers. Dozer was very good till we got to nested objects. Most of the times, we had to use custom mappers and that's where things got nasty. So we replaced it with another mapper, which I don't recall right now.
Any way, may be it was because we were still evaluating Dozer and other O2O mappers and was short of time... :)