Mapping concrete types from its base mapping type.
Let's take a source base type Entity, two its subtypes (FooEntity, BarEntity), for a destination take a base class Dto and two its subtypes (FooDto, BarDto). To create mapping that handles this polymorphic scenario, define a discriminator and register subtype mappings to the supertype via mapSubtype.
Register subtypes to the base type map via mapSubtype. Subtype map automatically inherits from its base so there is no need to explicitly define base/subtypes via includeBase or include.
For the discriminator we simply use read only property discriminator that is defined on both source subtypes. We can also exclude this property from mapping to the destination object.
Perform mapping against the base mapping token EntityToDto.
constfooSource=newFooEntity();fooSource.property ='123';fooSource.createdAt ='2020-01-01';constfoo=mapper.map(EntityToDto, fooSource) asFooDto;// "foo" is instance of "FooDto" and have following properties:// {// property: '123',// fooProperty: 123,// createdAt: '3020-01-01'// }constbarSource=newBarEntity();barSource.property ='123';barSource.createdAt ='2020-01-01';constbar=mapper.map(EntityToDto, barSource) asBarDto;// "bar" is instance of "BarDto" and have following properties:// {// property: '123',// barProperty: 123,// createdAt: '3020-01-01'// }