package cz.vhromada.converter.dozer;

import cz.vhromada.converter.AbstractConverter;

import com.github.dozermapper.core.Mapper;
import org.springframework.util.Assert;

/**
 * A class represents converter via Dozer.
 *
 * @author Vladimir Hromada
 */
public class DozerConverter extends AbstractConverter {

    /**
     * Dozer mapper
     */
    private final Mapper mapper;

    /**
     * Creates a new instance of DozerConverter.
     *
     * @param mapper dozer mapper
     * @throws IllegalArgumentException if dozer mapper is null
     */
    public DozerConverter(final Mapper mapper) {
        Assert.notNull(mapper, "Dozer mapper mustn't be null.");

        this.mapper = mapper;
    }

    @Override
    protected <T> T convertObject(final Object source, final Class<T> clazz) {
        return mapper.map(source, clazz);
    }

}
