All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alon.spring.crud.api.controller.input.mapper.ModelMapperInputMapper Maven / Gradle / Ivy

Go to download

Fornece implementação básica e expansível para criação API's CRUD com Spring Boot e Spring Data JPA.

There is a newer version: 1.0.9
Show newest version
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);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy