Skip to content

Mapping property with underscore to record with constructor #388

Description

@RobThree

First of all: thanks for this great library!

I think I have stumbled upon a bug; if not then I apologize but I don't think this is by design?

using Mapster;

TypeAdapterConfig.GlobalSettings.Default.NameMatchingStrategy(NameMatchingStrategy.Exact);
var e = new MyEntity
{
    Name = "Foo",
    Some_Value = "Bar"
};
var works = e.Adapt<MyDTO>();
var fails = e.Adapt<MyDTOWithConstructor>();

public record MyEntity
{
    public string Name { get; init; } = null!;
    public string Some_Value { get; init; } = null!;
}

public record MyDTO
{
    public string Name { get; init; }
    public string Some_Value { get; init; }
};


public record MyDTOWithConstructor
(
    string Name,
    string Some_Value
);

Mapping MyEntity to MyDTO works fine, as expected. However, when mapping to MyDTOWithConstructor the Some_Value property is not mapped. I have tried some other NameMatchingStrategy values but none seem to help. When I remove the underscore from the entity and DTO accordingly then everything works fine. I could also use explicit mappings. However, I have a LOT of entities and DTO's and I was hoping to keep it as simple as possible. I'm not sure if this behavior is by design but, at least, in my opinion, it doesn't seem very consistent?

Oh, using Mapster 7.2.0.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions