Mapster icon indicating copy to clipboard operation
Mapster copied to clipboard

Property not Getting Mapped

Open IPdotSetAF opened this issue 10 months ago • 3 comments

Hey, there. I encountered an strange mapping bug, i am literally mapping from the same type to itself but an specific nested property gets null (Order.Payment.CVV)

here is the code:

public record CreateOrderRequest(OrderDTO Order);

public record CreateOrderCommand(OrderDTO Order) ;

public record OrderDTO
    (
    Guid Id,
    Guid CustomerId,
    string OrderName,
    AddressDTO ShippingAddress,
    AddressDTO BillingAddress,
    PaymentDTO Payment,
    OrderStatus Status,
    List<OrderItemDTO> OrderItems
    );

public record PaymentDTO
    (
    string CardName,
    string CardNumber,
    string Expiration,
    string CVV,
    int PaymentMethod
    );

public void test(CreateOrderRequest request)
        {
            var tmp = request.Adapt<CreateOrderCommand>();
        }

Mapster Version: 7.4.0 .Net Version: 8

PS. I have debugged the code and the CVV field does have a value before mapping

IPdotSetAF avatar Feb 02 '25 09:02 IPdotSetAF

@IPdotSetAF yes, i hope it wil be fix in the next release. this setting should help you


 TypeAdapterConfig<PaymentDTO, PaymentDTO>
     .NewConfig()
     .NameMatchingStrategy(NameMatchingStrategy.IgnoreCase)


DocSvartz avatar Feb 02 '25 17:02 DocSvartz

Thanks @DocSvartz for the fast reply and recommendation. I would also like to start contributing in the project. if there was any chance feel free to mention me.

IPdotSetAF avatar Feb 02 '25 20:02 IPdotSetAF

linked #746

@andrerav @stagep This is because the Constructor Parameter Names are forced to PascalCase. Then Name Matching Strategy is no longer able Match Parametr and Property from source , since the name does not match.

I found a solution, it will be based on #769 Since it requires an explicit definition that mapping of constructor parameters is performed.

But perhaps there is a simpler solution)

DocSvartz avatar Feb 10 '25 10:02 DocSvartz