B
B
Biaci_Anj2021-08-24 23:38:45
Java
Biaci_Anj, 2021-08-24 23:38:45

Where should the DTO -> Entity conversion methods be and vice versa?

I placed methods in services. Convenient, but there was a problem during testing. The DTO conversion method is called in almost every service method. And now, when testing, I have to check each time if the result matches the desired one, instead of just verify whether the method was called and that's it ( verify cannot be called not on a mock).
There was an idea to transfer the method to a separate class, but I am weak in good practices.
Tell me, please, where would it be correct to transfer these conversion methods?
Should I create a separate mapper package with classes in it? Let's say the EmployeeMapper class has two methods toEmployee, toEmployeeDTO? Am I thinking right?

PS maptract can't use

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
BorLaze, 2021-08-25
@Biaci_Anj

Should I create a separate mapper package with classes in it? Let's say the EmployeeMapper class has two methods toEmployee, toEmployeeDTO? Am I thinking right?

Yes.
You can go on and on about why this is so, but I don't really see the point.

A
acwartz, 2021-08-25
@acwartz

In a MagicDTO service encapsulating a ModelMapper . For examples here . And forget all these toEntity, toDTO like a bad dream.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question