BeforeMap
As the name suggests, beforeMap()
sets up a MapCallback
to be called before the map operation.
Configure on Mapping
Pass beforeMap()
in createMap()
to sets up the MapCallback
createMap(
mapper,
User,
UserDto,
beforeMap((source, destination) => {})
);
Configure on map()
Pass beforeMap
in MapOptions
when calling map()
to sets up the MapCallback
mapper.map(user, User, UserDto, {
beforeMap: (source, destination) => {},
});
info
beforeMap()
onmap()
has precedence overMapping
- For
mapArray
(and its variants),beforeMap()
onMapping
is ignored because it would be bad for performance if we runbeforeMap
for each and every item of the array.beforeMap()
onmapArray()
will be invoked with(sourceArray, [])
instead
What about preMap
?
When create the Mapper
, we can customize the preMap
function on the MappingStrategy
. The differences between preMap
and beforeMap
are:
preMap
runs before every map operation- There is only one
preMap
perMapper
preMap
runs BEFOREbeforeMap