title: MapStruct : Nested Iterable to Non-Iterable mapping?
body: <p>I found this example about Iterable to Non-Iterable mapping using Qualifier :</p>
  
  <p><a href="https://github.com/mapstruct/mapstruct-examples/tree/master/mapstruct-iterable-to-non-iterable" rel="nofollow noreferrer">https://github.com/mapstruct/mapstruct-examples/tree/master/mapstruct-iterable-to-non-iterable</a></p>
  
  <p>But how to make this mapping able to map nested properties (using dot annotation)?</p>
  
  <p>E.g. mapping the field xyz of first element of a collection in the source object to a plain field on the target object?</p>
  
  <p>The example define a Qualifier</p>
  
  <pre><code>@Qualifier  
  @Target(ElementType.METHOD)  
  @Retention(RetentionPolicy.SOURCE)  
  public @interface FirstElement {
  }
  </code></pre>
  
  <p>then define a Custom Mapper</p>
  
  <pre><code>public class MapperUtils {
      @FirstElement
      public &lt;T&gt; T first(List&lt;T&gt; in) {
          if (in != null &amp;&amp; !in.isEmpty()) {
              return in.get(0);
          }
          else {
              return null;
          }
      }
  }
  </code></pre>
  
  <p>and, finally, the mapping is defined as</p>
  
  <pre><code>@Mapping(target = "emailaddress", source = "emails", qualifiedBy = FirstElement.class )
  </code></pre>
  
  <p>But if I would like to extract from the first element of emails collection a specific field, e.g. like I would have done with code <code>emails.get(0).getEmailAddress</code>?</p>
  
  <p>For example, I expect to write a mapping like this  :</p>
  
  <pre><code>@Mapping(target = "emailaddress", source = "emails[0].emailAddress")
  </code></pre>