title: How to map Collections in Mapstruct when generic type has Inheritance structure?
body: <p>I've the following bean structure in my project.</p>
  
  <pre><code> public class Account{
         // properties
         // setters
         // getters
      }
  
     public class AccountType1 extends Acccount{
         // properties
         // setters
         // getters
     }
  
      public class AccountType3 extends Acccount{
         // properties
         // setters
         // getters
     }
  
     public class CustomerProfile {
         Customer customer;
         List&lt;Account&gt; accounts;
         List&lt;Service&gt; services;
  
     }
  </code></pre>
  
  <p>I've similar structure for Customer and services. One parent and multiple implementation. My application is a middle ware application. I don't know what kind of run time objects our app gets from other webservice calls(Bean model is same across application). List can contain any implementation. It can either be Account or AccountType1 or AccountType2. Same is the case with Service. Parent will have common fields and each implementation will have specific fields. We will have a new flow for each new client i.e., consumer. Also field requirement is different. So we need to have separate CustomerProfile and corresponding Account and Service mappers. Now for client1, they may need generic Account or AccountType1 or AccountType2 or AccountTypeN or all of them. So code should be generic like whatever type of classes I give {AccountType1.class, AccounTypeN.class} in config, it should map those objects only from the list. Since AccountType1 extends Account, It should also take care of parent class fields. I'm currently doing this following way.</p>
  
  <pre><code>    @Mapper(config = GlobalConfig.class)
      public interface CustomerProfileMapper{
  
      @Mappings({
          @Mapping( target = "customer", source = "customer"),
          @Mapping( target = "accounts", source = "accounts"),
          @Mapping( target = "services", source = "services")
      })
      CustomerProfile mapCustomerProfile(CustomerProfile customerProfile);
  
      @IterableMapping(qualifiedByName = "mapAccount")
      List&lt;Account&gt; mapAccounts(List&lt;Account&gt; accounts);
  
      @Named("mapAccount")
      default Account mapAccount (Account account){
  
         if(account instanceof AccountType1){
              mapAccountType1((AccountType1)account);
          }
         else if(account instanceof AccountType2){
              mapAccountType2((AccountType2)account);
          }
         else {
              mapBaseAccount(account);
          }
      }
  
     @Mappings{...}
     AccountType1 mapAccountType1(AccountType1  account);
  
     @Mappings{...}
     AccountType2 mapAccountType2(AccountType2  account);
     }
  
     @Mappings{...}
     Account mapBaseAccount(Account  account);
  
  }
  </code></pre>
  
  <p>But This code will be redundant as I've to write for  each flow for different CustomerProfileMappers. I want code to be generic and can used as a configuration. Re-usability is the concern here. How to address this problem? Basically I want to do something like below.</p>
  
  <pre><code>@IterableMapping( mappingClasses= {AccountType1.class, AccountType2.class, Account.class})
      List&lt;Account&gt; mapAccounts(List&lt;Account&gt; accounts);
       @Mappings{...}
         AccountType1 mapAccountType1(AccountType1  account);
  
         @Mappings{...}
         AccountType2 mapAccountType2(AccountType2  account);
         }
  
         @Mappings{...}
         Account mapBaseAccount(Account  account);
  </code></pre>
  
  <p>So mapStruct should generate code like how I handled this currently. It should generate the mapping method to handle all the specified classes defined in mappingClasses property. It should also look for individual class specific mapping methods in the mappers. If found call them or else generate a mapping method.  This is required because I have similar thing with Customer and Service. I don't want too much hand written code in mappers and We have tens of CustomerProfileMappers different for each flow. And they keep increasing with each release. I've gone through the complete technical documentation of MapStruct. But i couldn't find a way to do this. Or this could be a new FR?</p>