Skip to content

Multiple sources - Mapping required for every member #501

@ChristopheLionet

Description

@ChristopheLionet

Issue #180 shows how to solve the need for multiple sources using tuples, and that it is implemented in Mapster 5.0.

However, using multiple sources as stated in the docs introduces a heavy constraint, which is to map every member manually.
In the following code, dto.CommonValue is null if not explicitly mapped in the config.

record PocoA(string SpecificValue);      
record PocoB(int CommonValue);                
record Dto(int CommonValue, int SumValue);  
//...

TypeAdapterConfig.GlobalSettings.NewConfig<(PocoA, PocoB), Dto>()                                                 
    .Map(dto => dto.SumValue, pocoTuple => pocoTuple.Item1.SpecificValue + pocoTuple.Item2.CommonValue);    
// ...

var dto = mapper.Map<(PocoA, PocoB), Dto>(pocoA, pocoB);  // dto.CommonValue is null

Is there a solution to this?
It breaks the workflow in some large objects. If a single parameter needs an additional source, every single member needs to be mapped manually.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions