33 lines
695 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.List;
import java.util.stream.Collectors;
2020-04-19 21:02:17 +02:00
/**
* This is a helper class that contains method for custom 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> source, Class<T> targetClass) {
2020-04-19 21:02:17 +02:00
return source
.stream()
.map(element -> modelMapper.map(element, targetClass))
.collect(Collectors.toList());
2020-04-19 21:02:17 +02:00
}
}