Files
java-tutorials/java-collections-conversions-2/src/main/java/com/baeldung/modelmapper/MapperUtil.java
T

35 lines
708 B
Java
Raw Normal View History

package com.baeldung.modelmapper;
2020-04-19 21:02:17 +02:00
import org.modelmapper.ModelMapper;
import java.util.ArrayList;
import java.util.List;
/**
* This is a helper class that contains methods for generic mapping of the users list.
* Initially, an instance of ModelMapper was created.
2020-04-21 21:29:38 +02:00
*
2020-04-21 22:26:22 +02:00
* @author Sasa Milenkovic
2020-04-19 21:02:17 +02:00
*/
public class MapperUtil {
private static ModelMapper modelMapper = new ModelMapper();
private MapperUtil() {
}
public static <S, T> List<T> mapList(List<S> sourceList, Class<T> target) {
2020-04-19 21:02:17 +02:00
List<T> targetList = new ArrayList<T>();
for (S source : sourceList) {
targetList.add(modelMapper.map(source, target));
}
return targetList;
}
}