P
P
prizrak392017-04-05 19:43:40
Java
prizrak39, 2017-04-05 19:43:40

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

2 answer(s)
R
reus, 2017-04-06
@reus

show a test case

P
prizrak39, 2017-04-06
@prizrak39

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 question

Ask a Question

731 491 924 answers to any question