Refactoring code in com.baeldung.modelmapper package
This commit is contained in:
+2
-14
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user