Skip to main content

MapDefer

mapDefer() is a special type of MemberMapFunction that can be used to defer another MemberMapFunction based on some logic in forMember()

Call mapDefer() and pass in the DeferFunction which will be called with the sourceObject. We can then use this sourceObject and return another MemberMapFunction

createMap(
mapper,
User,
UserDto,
forMember(
(destination) => destination.profile,
mapDefer((source) => {
if (source.profile.type === 'A')
return mapWith(
ProfileDto,
ProfileA,
(source) => source.profile
);
return mapWith(ProfileDto, Profile, (source) => source.profile);
})
)
);

mapDefer() sets the TransformationType to TransformationType.MapDefer