question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Configure a mapper from string to List<string> and from List<string> to string

See original GitHub issue

I am trying to configure Napster of these two entities to pass from List to string but it gives me an error. any ideas. Thank you

public class  EntidadVM 
     { public List<string> CCC}

public class  EntidadDto 
     { public string CCC}

I’m doing them like this, but it gives me an error

TypeAdapterConfig<MailingDto, MailingVM>.NewConfig()
 .Map(dest => dest.CCC, src => new List<string>(src.CCC.Split(',')).ToList() );

TypeAdapterConfig<MailingDto, MailingVM>.NewConfig()
 .Map(dest => dest.CCC, src => src.CCC.Split(',').ToList() );

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
devbasedcommented, Jun 2, 2022

@ascariz

[TestMethod]
public void MapToTarget()
{
    var dto = new EntidadDto { CCC = "one,two,three", };

    // expression tree cannot contain call which contains optional arguments, so specify explicitly
    var config = TypeAdapterConfig<EntidadDto, EntidadVM>.NewConfig()
        .Map(dest => dest.CCC, src => new List<string>(src.CCC.Split(',', StringSplitOptions.None)).ToList());
    var vm = dto.Adapt<EntidadVM>(config.Config);
    vm.CCC.ShouldBe(new[] { "one", "two", "three" });

    config = TypeAdapterConfig<EntidadDto, EntidadVM>.NewConfig()
        .Map(dest => dest.CCC, src => src.CCC.Split(',', StringSplitOptions.None).ToList());
    vm = dto.Adapt<EntidadVM>(config.Config);
    vm.CCC.ShouldBe(new[] { "one", "two", "three" });

    // or use after mapping
    config = TypeAdapterConfig<EntidadDto, EntidadVM>.NewConfig()
        .Ignore(x => x.CCC)
        .AfterMapping((src, dest) => dest.CCC = src.CCC.Split(',').ToList());
    vm = dto.Adapt<EntidadVM>(config.Config);
    vm.CCC.ShouldBe(new[] { "one", "two", "three" });

    config = TypeAdapterConfig<EntidadDto, EntidadVM>.NewConfig()
        .Ignore(x => x.CCC)
        .AfterMapping((src, dest) => dest.CCC = new List<string>(src.CCC.Split(',')).ToList());
    vm = dto.Adapt<EntidadVM>(config.Config);
    vm.CCC.ShouldBe(new[] { "one", "two", "three" });
}
0reactions
devbasedcommented, Jul 2, 2023

@ignacioerrico I don’t have the right to manage the issue 😅 It just turned out that I’m subscribed to this topic, so I quickly replied to you 😊

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mapping string to List<string> and vice versa using ...
I have no idea how to map between these 2. My current setup : Mapper.CreateMap<UserEditViewModel, User>().ReverseMap();. c# · asp ...
Read more >
How to convert Map<String,List<String>> to Map< ...
You need to create a new user for each iteration through the loop: for(String uMap : usersMap. ... Values__c = string.join(usersMap.get(u.
Read more >
Convert List<Map<String,String>> to List<String> - Java
Convert List > to List by values from map.
Read more >
Jackson - Convert JSON array string to List
Few Jackson examples to convert a JSON array string to a List // JSON array string ... 1.2 Create an object to map...
Read more >
Converting a List to String in Java
In this quick tutorial, we'll explain how to convert a List of elements to a String. This can be useful in certain scenarios,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found