com.alon.spring.crud.api.controller.input.mapper.ModelMapperInputMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of crud-api-base Show documentation
Show all versions of crud-api-base Show documentation
Fornece implementação básica e expansível para criação API's CRUD com Spring Boot e Spring Data JPA.
package com.alon.spring.crud.api.controller.input.mapper;
import com.alon.spring.crud.domain.model.BaseEntity;
import org.modelmapper.ModelMapper;
public class ModelMapperInputMapper> implements InputMapper {
private final ModelMapper modelMapper;
private final Class outputType;
public ModelMapperInputMapper(Class outputType) {
this(outputType, new ModelMapper());
}
public ModelMapperInputMapper(Class outputType, ModelMapper modelMapper) {
this.outputType = outputType;
this.modelMapper = modelMapper;
}
public ModelMapper getModelMapper() {
return modelMapper;
}
@Override
public O map(I input) {
if (outputType.isAssignableFrom(input.getClass()))
return (O) input;
return modelMapper.map(input, outputType);
}
@Override
public void map(I source, O destination) {
modelMapper.map(source, destination);
}
}