Skip to content

RequireExplicitMapping is not working as expected. #783

Open
@JasonGrass

Description

@JasonGrass

When converting between two class, both of which have a property named MyProperty with different types (one is string and the other is int),
I have configured RequireExplicitMapping = true.

I expected an exception to occur during the Compile phase, indicating that I should explicitly configure the conversion between these two properties. However, that did not happen. The error only occurs at runtime if the conversion fails.

Is there any way to avoid this situation?

Mapster version: 7.4.0

// PatientInformation
public string MyProperty { get; set; } = "";

// PatientInfoViewObject
public int MyProperty { get; set; }
  public static void ConfigureMappings()
  {
      TypeAdapterConfig.GlobalSettings.RequireExplicitMapping = true;
      TypeAdapterConfig.GlobalSettings.RequireDestinationMemberSource = true;

      ConfigurePatientInfoMappings();

      //  expect an exception here
      TypeAdapterConfig.GlobalSettings.Compile();

      // test code
      var info = new PatientInformation();
      info.MyProperty = "test";
      var viewObject = info.Adapt<PatientInfoViewObject>();
  }

  private static void ConfigurePatientInfoMappings()
  {
      TypeAdapterConfig<PatientInformation, PatientInfoViewObject>.NewConfig();

      TypeAdapterConfig<PatientInfoViewObject, PatientInformation>.NewConfig();
  }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions