MapsterMapper / Mapster

A fast, fun and stimulating object to object Mapper
MIT License
4.23k stars 325 forks source link

Mapster tool How to declare custom mapping. #682

Open Alexandr-Pletnev opened 4 months ago

Alexandr-Pletnev commented 4 months ago

Hello all.

We want to use mapster tool to auto-generate DTOs and Mappers. But we don't understand how we can declare custom mapping.

For example:

var builder = config.AdaptTo("[name]Dto", MapType.Map)
      .ForType<ProjectDocument>(cfg =>
      {
          cfg.Map(src => src.ProjectXml, typeof(string), "ProjectXmlAsJson", srcValue => "some logic to return dest value");

      });

We want to implement "some logic to return dest value". We need to serialize src value to string.

How can we do it?