Maps an object to another via getters and setters methods
- Maps DTO to Model/Entity object
- Maps Model/Entity to DTO object
- Maps nested objects
- Maps nested Lists, Sets and Maps
- Can map any object to any object if it follows the restrictions
- Caches objects getters and setters methods for improve performance
- Maps only corresponding origin object field if it has getter method and destination object have corresponding setter method
- Returned class should have accessible constructor without parameters
- Getter and setter methods name should have more than 3 characters
- Java 1.7+
@Entity
public class Student {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String name;
private String email;
private String password;
private LocalDate birthday;
@Column(name = "Curso_id")
private int courseId;
@ManyToOne
@JoinColumn(name = "Curso_id", insertable = false, updatable = false)
private Course course;
// getters, setters, equals, hashCode
}
public class StudentDTO {
private int id;
private String name;
private String email;
private String password;
private LocalDate birthday;
private int courseId;
// getters, setters, equals, hashCode
}
StudentDTO studentDTO = new StudentDTO();
studentDTO.setId(id);
studentDTO.setName(name);
studentDTO.setEmail(email);
studentDTO.setPassword(password);
studentDTO.setBirthday(birthday);
studentDTO.setCourseId(courseId);
Student student = ObjectMapper.map(studentDTO, Student.class);
Student student = new Student();
student.setId(id);
student.setName(name);
student.setEmail(email);
student.setPassword(password);
student.setBirthday(birthday);
student.setCourseId(courseId);
StudentDTO studentDTO = ObjectMapper.map(student, StudentDTO.class);
List<Discipline> disciplineList = execute(query, parameters);
List<DisciplineDTO> disciplineDTOList = ObjectMapper.map(disciplineList, DisciplineDTO.class)