Answer the question
In order to leave comments, you need to log in
How to unify the mapping of the same classes in different packages?
Good afternoon.
The project uses several third-party services (I cannot change them). The task is to implement the mapping of my object to service objects, the objects are the same, but they are from different packages. That is code duplication.
Is it possible to avoid this, to simplify the task?
PS perhaps badly explained, ready to show a test case.
Answer the question
In order to leave comments, you need to log in
Here is an example of mapping. The Person classes are the same, just located in different packages.
public class OrderMapper {
public static Person orderMapperPerson1(Order order) {
Person person = new Person();
person.setFirstName(order.getFirstName());
person.setLastName(order.getLastName());
person.setAge(order.getAge());
return person;
}
public static com.company.package2.Person orderMapperPerson2(Order order) {
com.company.package2.Person person = new com.company.package2.Person();
person.setFirstName(order.getFirstName());
person.setLastName(order.getLastName());
person.setAge(order.getAge());
return person;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question