-
Notifications
You must be signed in to change notification settings - Fork 321
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
Cannot map properties that have differt names and init access modifier #656
Comments
linked #422 @nicoarm93 @andrerav location of this bug found ) PR with fix is open #658 |
In my case similar regression between 7.4.0 and 7.3.0 (Mapster throws a NullReferenceException) is not related to using Mapster;
TypeAdapterConfig<Core.RootSource.NestedSource, Core.RootDestination.NestedDestination>
.NewConfig()
.Map(dest => dest.NameDest, src => src.NameSrc);
var dest = new Core.RootDestination { MyProperty = null };
var mapped = Core.RootSource.Create().Adapt(dest);
Console.WriteLine(mapped);
namespace Core
{
public class RootSource
{
public required NestedSource? MyProperty { get; set; }
public static RootSource Create()
{
return new RootSource
{
MyProperty = new NestedSource
{
NameSrc = "NotEmptyString"
}
};
}
public class NestedSource
{
public required string NameSrc { get; set; }
}
}
public class RootDestination
{
public NestedDestination? MyProperty { get; set; }
public override string ToString()
{
return $"{nameof(RootDestination)}.{nameof(MyProperty)}={MyProperty?.NameDest}";
}
public class NestedDestination
{
public string? NameDest { get; init; }
}
}
} |
Hello @Mat3oo, @andrerav Working Code :
Non-working code (throws a NullReferenceException):
|
Hi,
I have a problem with version 7.4. If I want to map two properties with different names and the destination has a different name and the
init
modifier, Mapster throws a NullReferenceException. This happens when in the configuration of Mapster I setPreserveReference
totrue
.Here's the code
And here's the mapping
(The problem does not manifest if the properties have the same name or another modifier (
set;
orprivate set;
)This code works fine with version 7.3
The text was updated successfully, but these errors were encountered: