Created
October 8, 2021 16:08
-
-
Save taljacob2/86c096af1b12b7caaa79109f99319ca1 to your computer and use it in GitHub Desktop.
This Component is used for mapping Objects. Mainly, for
mapping DTOs to Entities / Entities to DTOs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.tal.spring.bean.mapper; | |
import org.modelmapper.ModelMapper; | |
import org.springframework.stereotype.Component; | |
import java.util.List; | |
import java.util.stream.Collectors; | |
/** | |
* This {@link Component} is used for mapping {@code Object}s. Mainly, for | |
* mapping DTOs to Entities / Entities to DTOs. | |
* <p> | |
* Requires: | |
* | |
* <pre> | |
* <i>Gradle:</i> | |
* dependencies { | |
* <b> compileOnly 'org.modelmapper:modelmapper:2.3.5' </b> | |
* } | |
* </pre> | |
* </p> | |
* | |
* @author Tal Jacob | |
* @version 1.0 | |
* @see org.modelmapper.ModelMapper | |
*/ | |
@Component public class Mapper extends ModelMapper { | |
public <S, T> List<T> mapList(List<S> source, Class<T> targetClass) { | |
return source.stream().map(element -> this.map(element, targetClass)) | |
.collect(Collectors.toList()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment