Mapping interface between POJOs and DTOs Following up on this question DTO interfaces for implementing web service integration I came up with this implementation.

Data Transfer Object interface following a java.util.Map protocol. The implementation uses Guava's ForwardingMap.

public interface Dto&lt;K, V&gt; extends Map&lt;K, V&gt; {}

public class DtoImpl&lt;K, V&gt; extends ForwardingMap&lt;K, V&gt; implements Dto&lt;K, V&gt; {

    private final Map&lt;K, V&gt; delegate;

    @Override
    protected Map&lt;K, V&gt; delegate() {
        return this.delegate;
    }

    private DtoImpl(final Map&lt;K, V&gt; map) {
        this.delegate = map;
    }

    public static &lt;K, V&gt; Dto&lt;K, V&gt; of(final Map&lt;K, V&gt; map) {
        return new DtoImpl&lt;K, V&gt;(map);
    }
}


Mapper interface between a type T and a Dto.

public interface Mapper&lt;T&gt; {

    public &lt;K, V&gt; Dto&lt;K, V&gt; toDto(T obj);

    public &lt;K, V&gt; T fromDto(Dto&lt;K, V&gt; dto, Class&lt;T&gt; clazz);
}

public class MapperImpl&lt;T&gt; implements Mapper&lt;T&gt; {

    public &lt;K, V&gt; Dto&lt;K, V&gt; toDto(T obj) {
        ObjectMapper objectMapper = new ObjectMapper();
        Map&lt;K, V&gt; map = objectMapper.convertValue(obj, Map.class);
        return DtoImpl.of(map);
    }

    public &lt;K, V&gt; T fromDto(Dto&lt;K, V&gt; dto, Class&lt;T&gt; clazz) {
        ObjectMapper objectMapper = new ObjectMapper();
        T obj = objectMapper.convertValue(dto, clazz);
        return obj;
    }

}


Comments and improvements on this implementation are welcome!
Is it worth it to define the Mapper interface with something like interface Mapper&lt;T, K, V&gt;? Ideally I would like to say interface Mapper&lt;T, S extends Dto&lt;K, V&gt;&gt; but this is not possible or is it?
public interface Dto&lt;K, V&gt; extends Map&lt;K, V&gt; {} why don't you use simply a Map? Again, it is the same discussion related to marker interfaces we already had in your original question.

I'd define Mapper in the following way:

public interface Mapper&lt;T, K, V&gt; {
    public Dto&lt;K, V&gt; toDto(T obj);
    public T fromDto(Dto&lt;K, V&gt; dto);
}


I don't understand the reason why you need MapperImpl. What you need are concrete classes imlementing your interface for your specific types.

Imagine you want to map a Date to a Map&lt;String,Integer&gt;. You need something like this:

class DateMapper implements Mapper&lt;Date, String, Integer&gt;
{
    public Dto&lt;String, Integer&gt; toDto(Date date)
    {
        Dto&lt;String, Integer&gt; dto = new Dto&lt;String, Integer&gt;();
        dto.put("Day", date.Day());
        dto.put("Month", date.Month());
        dto.put("Year", date.Year());
    }

    public Date fromDto(Dto&lt;String, Integer&gt; dto)
    {
        return new Date(dto.get("Year"), dto.get("Month"), dto.get("Day"));
    }
}


I think that at this point you might be thinking at how you could obtain an instance of DateMapper. I think you should use some sort of factory or build it using reflection depending on what is better in your use case.