Refactoring code in com.baeldung.modelmapper package

This commit is contained in:
Sasa M
2020-04-25 21:57:43 +02:00
parent 32d1cc8a13
commit a5264182cd
5 changed files with 24 additions and 35 deletions
@@ -1,39 +1,27 @@
package com.baeldung.modelmapper;
import org.modelmapper.ModelMapper;
import org.modelmapper.convention.MatchingStrategies;
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. In the static block we set the matching configuration to STRICT.
* Initially, an instance of ModelMapper was created.
*
* @author Sasa Milenkovic
*/
public class MapperUtil {
private static ModelMapper modelMapper = new ModelMapper();
static {
modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
}
private MapperUtil() {
}
public static <S, T> T mapTo(final S source, final Class<T> target) {
return modelMapper.map(source, target);
}
public static <S, T> List<T> mapList(final List<S> sourceList, final Class<T> target) {
public static <S, T> List<T> mapList(List<S> sourceList, Class<T> target) {
List<T> targetList = new ArrayList<T>();
for (S source : sourceList) {