Condition
Call condition() to conditionally execute the auto-map operation for the property (e.g: Source#propertyName -> Destination#propertyName) by passing in a predicateFn that will be called with the sourceObject
createMap(
mapper,
User,
UserDto,
forMember(
(destination) => destination.petName,
condition((source) => source.hasPet)
)
);
If source.hasPet is evaluated to truthy, then destination.petName will be mapped with source.petName. Otherwise, destination.petName will be undefined.
Default Value
condition() accepts an optional defaultValue. In the case that the predicateFn is evaluated to falsy, the defaultValue will be used to mapped to the configured property instead of undefined
createMap(
mapper,
User,
UserDto,
forMember(
(destination) => destination.petName,
condition((source) => source.hasPet, 'default pet name')
)
);
condition() sets the TransformationType to TransformationType.Condition