Skip to content

Properties that contain capitalized abbreviations cannot also be mapped in the fluent API when mapping to a record #370

Description

@CerebralUnit

There are several properties in the Adverse record on the domain model that have abbreviations and are therefore capitalized (e.g. HDMAReasons.) Regardless of the naming strategy Exact, IgnoreCase, Flexible etc.. Mapster will fail execute a custom mapping unless a Pascal case version of the property is passed in for the destination object. Using x => x.HDMAReasons causes the mapper to throw a configuration error saying that there is neither a mapping nor an Ignore for HdmaReasons. Neither object being mapped has that casing. Example of the code that finally worked below.

config.MapDependentTo<Adverse, Domain.Adverse>()
.MapToConstructor(true)
.NameMatchingStrategy(NameMatchingStrategy.IgnoreCase)
.Map("HmdaReasons", src => src.HMDAReasons.Select(x => x.EnumValue))

Activity

  1. andrerav commented on Feb 19, 2022

    @andrerav
    Member

    Might be related to #388.

  2. JMPSequeira commented on Jun 28, 2022

    @JMPSequeira

    @CerebralUnit could you provide the models used for the issue? And please clarify if the specific problem only occurs when mapping to a constructor.

  3. self-assigned this
    on Jan 7, 2023
  4. ventii commented on Mar 7, 2023

    @ventii

    Had the exact same issue - fields with consecutive capital letters in a C# record constructor are not mapped even when the source record/class has the same field with the same name.

    non working example:

    public record MySourceRecord(DateTime ValidFromUTC);
    
    public record MyDestinationRecord(DateTime ValidFromUTC);
    
    // having the following config
    config.NewConfig<MySourceRecord, MyDestinationRecord>();
    

    got it to work by doing the following changes:

    // change property name of destination record to PascalCase
    public record MyDestinationRecord(DateTime ValidFromUtc);
    
    // update config to specify mapping
    
    config.NewConfig<MySourceRecord, MyDestinationRecord>()
                    .Map(dest => dest.ValidFromUtc, src => src.ValidFromUTC);
    

    I was going crazy as I initially thought it was some bug with DateTime.

    Is this a known issue please?

  5. andrerav commented on Mar 7, 2023

    @andrerav
    Member

    @ventii Yes this is a known issue, the name matching strategy does not seem to be working as intended.

  6. andrerav commented on Mar 7, 2023

    @andrerav
    Member

    See also #388.

  7. added 5 commits that reference this issue on May 21, 2023
    5cf7259
    45a0409
    6c01137
    591fb46
    45d012e
  8. added a commit that references this issue on May 29, 2023
    cc81763
  9. leseneda commented on Jul 2, 2024

    @leseneda

    I solved my issue using the following code line;

    globalSettings.Default.NameMatchingStrategy(NameMatchingStrategy.Flexible);

    Mapster 7.4.0

    Hope this helps.

  10. Berkay-Sari commented on Dec 12, 2024

    @Berkay-Sari

    TypeAdapterConfig.GlobalSettings.Default.NameMatchingStrategy(NameMatchingStrategy.IgnoreCase);
    This fix worked for me. Problem was that the name of my unmapped prop was in uppercase letters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions