title: MapStruct Map Object to List
body: <p>I am trying to use Mapstruct to map source object to a target list. What should be a clean mapstruct way of doing this?</p>
  
  <p>Below are my DTO's.</p>
  
  <p>Source DTO</p>
  
  <pre><code>@Data
  class Source
  {
  
  String a;
  
  String b;
  
  String C;
  
  }
  
  </code></pre>
  
  <p>Target DTO</p>
  
  <pre><code>@Data
  class Target
  {
  
  String name;
  
  List&lt;Child&gt; customList;
  
  }
  
  @Data
  class Child
  {
  
  String attr1;
  
  boolean attr2;
  
  }
  
  </code></pre>
  
  <p>I am facing issues with Mapper Class. Trying to achieve something like below.</p>
  
  <pre><code>public interface CustomMapper
  {
  
  @Mapper(target="customList" expression="java(new Child(a,false))"
  @Mapper(target="customList"  expression="java(new Child(b,true))"
  @Mapper(target="customList"  expression="java(new Child(c,false))"
  Target sourceToTarget(Source source);
  
  
  }
  </code></pre>
  
  <p>I don't want to use qualifiedBy function like below to achieve this, as all conversion needs to be coded for each element.</p>
  
  <pre><code>List&lt;Child&gt; toList(Source source)
  {
     List&lt;Child&gt; customList = new ArrayList&lt;Child&gt;();
     customList.add(new Child(source.getA(),false));
     customList.add(new Child(source.getB(),true)); 
     customList.add(new Child(source.getC(),false));
  
      return customList;
  }
  </code></pre>