Hello:
I have an app where in a thread hierarchy (persisted entity) is modelled as follows (note that this could be a deeply nested hierarchy):
Thread
{
private key;
private rootKey;
private parentKey;
.. getters ..
.. setters ..
}
I have a DTO which has the following structure
ThreadDTO
{
private key;
private rootKey;
private parentKey;
ArrayList<ThreadDTO> childThreads;
... getters ...
... setters ...
}
I would like to convert the entity instances into the DTO. Are there any standard algorithms / best practices available that can be optimally be used for doing this transformation ?
Any feedback would be appreciated..
DTO are quite annoying, the best thing you can do with them is to create a method which takes a
Threadin parameter and copy the attributes, and another which will return aThreadwith a copy of the attributes.An other solution from Adam Bien is the Generic DTO, there is less security but also less copy/paste of in code.