Multiple occurances of classes in hierachy

14 views
Skip to first unread message

Björn Lindahl

unread,
Jan 13, 2021, 1:49:25 PM1/13/21
to modelmapper
How do you best handle the mapping between a database entity class structure to a data transfer object (DTO) class structure where classes can appear multple times in the hierarchy.

Let's say you have the database entity classes with JPA annotation which is left out here:

class DBCompany {
String companyName;
DBPerson employee;
DBHouse factory;
}

class DBPerson {
String Name;
DBHouse residentialBuilding;
}

And the corresponding DTO structure
class  DTOCompany {
String companyName;
DTOPerson employee;
DTOHouse factory;
}

class DTOPerson {
String Name;
DTOHouse residentialBuilding;
}

And then I want to use strict mapping when converting back and forth between the two hierarchies. Do I then have to define explicit mappings between each and every class member in the classes in order to be completely safe nothing get converted using wrong mapping? Or is it handled if you just name the class members identically?

Irfaan Hibatullah

unread,
Jan 22, 2021, 9:41:23 PM1/22/21
to model...@googlegroups.com
i think you have done with strict mapping and you have to call objectmapper map.
DBCompany entity = modelMapper.map(DTOCompany , DBCompany.class);

Object mapper automatically convert because DTO and entity have same name field..

Correct me if i am wrong and sorry for my english.



--
You received this message because you are subscribed to the Google Groups "modelmapper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modelmapper...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/modelmapper/0c2bfa51-54ad-4957-93ef-1c8fd255a333n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages