Moving com.baeldung.modelmmaper package to java-collections-conversations module

This commit is contained in:
Sasa M
2020-04-21 18:46:45 +02:00
parent 013a2cf899
commit 912d17c08b
7 changed files with 90 additions and 252 deletions

View File

@@ -0,0 +1,34 @@
package com.baeldung.modelmapper;
import org.modelmapper.AbstractConverter;
import org.modelmapper.Converter;
import org.modelmapper.PropertyMap;
import java.util.ArrayList;
import java.util.List;
/**
* @author sasam0320
* @description
* 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.
*/
public class UserPropertyMap extends PropertyMap<UserList, UserListDTO> {
Converter<List<User>, List<String>> converter = new AbstractConverter<List<User>, List<String>>() {
List<String> usernames = new ArrayList<>();
protected List<String> convert(List<User> users) {
users.forEach(user -> usernames.add(user.getUserName()));
return usernames;
}
};
@Override
protected void configure() {
using(converter).map(source.getUsers(), destination.getUsernames());
}
}