package com.baeldung.modelmapper; import org.modelmapper.AbstractConverter; import org.modelmapper.Converter; import org.modelmapper.PropertyMap; import java.util.ArrayList; import java.util.List; /** * UserPropertyMap class instantiates the converter to map the data from the user list to the user name list. * In the configuration method, we call a converter to do the mapping. * * @author Sasa Milenkovic */ public class UserPropertyMap extends PropertyMap { Converter, List> converter = new AbstractConverter, List>() { protected List usernames; @Override protected List convert(List users) { usernames = new ArrayList(); users.forEach(user -> usernames.add(user.getUsername())); return usernames; } }; @Override protected void configure() { using(converter).map(source.getUsers(), destination.getUsernames()); } }