I'm trying to map following source classes to target class using MapStruct.
Target Classes :
public class Response {
    private List<Customer> customer = new ArrayList<Customer>();
}
public class Customer {
    private String customerId;
    private List<Product> products = new ArrayList<Product>();
}
public class CustProduct {
    private String CustProductId;
    private String CustPdtName;
    private List<productDetail> CustProductDetails = new ArrayList<productDetail>();
}
Source Classes :
public class UserList {
    protected List<User> user;
}
public class User {
    protected String userId;
    protected List<String> productRefId;  //List of products for that particular user
}
public class ProductList {
    protected List<Product> product;
}
public class Product {
   protected String productId;       //Reference to productRefId
   protected String productName;
   protected List<Details> productDetails;
}
   
Mapper Interface :
 List<Customer> mapUser(List<User> user);
    @Mappings({
            @Mapping(target = "customerId", source = "userId”),
            @Mapping(target = "products", ignore = true)
    })
    Customer mapUser(User user);
    @Mappings({
        @Mapping(target = "CustProductId", source = "productId"),
        @Mapping(target = "CustPdtName", source = "productName"),
        @Mapping(target = "CustProductDetails", source = "productDetails")
})
CustProduct mapUser(Product product);
My problem is, I want to connect CustProduct with Customer For that, I tried AfterMapping like :
default void findProducts(User user, @MappingTarget Customer customer) {
            List<String> productIds = user.getproductRefId();
            List<CustProduct> custProducts = new ArrayList<>();
            for(int i=0; i<productIds.size();i++){
                    CustProduct custProduct = new CustProduct();
                    custProduct.setCustProductId(productIds.get(i));
                    //Here I want set productName and productDetails to custProduct Object(Iterating through ProductList and get from Product)
                    custProducts.add(custProduct);
                }
            }
            customer.setCustProducts(custProducts);
        }
    
Can anyone please help to fill out the comment section above? Or is there any other option to map these objects?
Edited : I tried the below solution but the interface implementation class itself changed.
 
     
     
    