-
Notifications
You must be signed in to change notification settings - Fork 334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handling Null source objects #60
Comments
Hi @Shah-123, Sorry for late reply. This need to be fixed. Thank you for report.
With above configuration, when user is null, function will return null instead of error. |
Hi !!
To: eswann/Mapster [email protected] Hi @Shah-123,Sorry for late reply.This need to be fixed. Thank you for report. |
I have no plan yet. Please specify both source type and destination type to solve problem for now. |
Mapster just silently ignores null references for example
if Postcode is null, it sets destination property as null and all is good. But what if we want to throw an exception when dealing with null references? Can't seem to find that configuration option anywhere. |
In our coding we have a situation where source object doesn't have any value. E.g. We are getting user information from database, but id pass is not valid, so user object is null.
One way if to sprinkle null check before invoking Adapt method
if (user != null)
{
_adapter.Adapt(user)
}
If there better way to handle Null object in Mapster?
I have seen that AutoMapper supports something like below:
Mapper.CreateMap<User, UserViewModel>()
.ConvertUsing();
class WsMembershipToDeMemberConverter
: AutoMapper.ITypeConverter<User, UserViewModel>
{
public UserViewModel Convert(AutoMapper.ResolutionContext context)
{
if (context == null || context.IsSourceValueNull)
{
return null;
}
}
Do we have any such support? Any thing one can suggest so we don't have to sprinkle null check in entire code base.
The text was updated successfully, but these errors were encountered: