Created
July 28, 2022 09:17
-
-
Save dehidehidehi/0ac6fcbb3cb9dfd6cedd3091aedbfb6c to your computer and use it in GitHub Desktop.
Contract for a generic dto to entity mapper from JHipster.
This file contains hidden or 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
import java.util.List; | |
import org.mapstruct.BeanMapping; | |
import org.mapstruct.MappingTarget; | |
import org.mapstruct.Named; | |
import org.mapstruct.NullValuePropertyMappingStrategy; | |
/** | |
* Contract for a generic dto to entity mapper. | |
* | |
* @param <D> - DTO type parameter. | |
* @param <E> - Entity type parameter. | |
*/ | |
public interface EntityMapper<D, E> { | |
E toEntity(D dto); | |
D toDto(E entity); | |
List<E> toEntity(List<D> dtoList); | |
List<D> toDto(List<E> entityList); | |
@Named("partialUpdate") | |
@BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE) | |
void partialUpdate(@MappingTarget E entity, D dto); | |
} |
This file contains hidden or 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
import org.mapstruct.*; | |
/** | |
* Mapper for the entity {@link ExampleEntity} and its DTO {@link ExampleEntityDTO}. | |
*/ | |
@Mapper(componentModel = "spring") | |
public interface ExampleEntityMapper extends EntityMapper<ExampleEntityDTO, ExampleEntity> {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment