Dead-simple object mapping in Java
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

mappify Build Status

Dead-simple object mapping in Java.


Standalone usage

  1. Add Maven dependency (or download and include jars from here)

The latest development version always available through Sonatype Snapshots repository.

  1. Define mapping provider(s)
class MappingProvider {
    public void mapFromSourceToTarget(Source source, Target target) { = "Target #" +;

NOTE: Each mapping provider can define arbitrary number of @Mapping-annotated methods.

  1. Create & configure Mapper instance
Mapper mapper = new HandcraftMapper();
mapper.register(new MappingProvider()); // call this method for each mapping provider you have
  1. Use it across the application
Target mappedTarget = Source(1), Target.class);
Set<Target> mappedTargets =
    mapper.mapToHashSet(Array.asList(new Source(2), new Source(3)), Target.class);

Integration with Spring

  1. Add Maven dependency
  1. Include the following line into your spring context configuration file
<import resource="classpath:mappify-handcraft-spring-context.xml"/>
  1. Define mapping provider(s)
public class EntityMappingProvider {

    public void mapToDTO(Entity entity, EntityDTO dto) {

    public void mapFromDTO(EntityDTO entityDTO, Entity entity, MappingContext context) {


NOTE: @MappingProvider extends @Controller. As a result, mapping providers are discoverable with Spring's <context:component-scan .../>. If you don't use it, just make sure mapping providers are wired into the context (e.g. by using <bean ... class="mapping provider class"/>).

  1. Call the Mapper
private Mapper mapper;
Entity entity = ...;
EntityDTO dto =, EntityDTO.class);

Testing with Mockito

Mapper mapper = mock(AbstractMapper.class, Mockito.CALLS_REAL_METHODS);
do...(...).when(mapper).map(any(), any(), anyString(), any(MappingContext.class));

Frequently Asked Question

  • Why does Mapper have mapToArrayList but no mapToLinkedList method?

    All mapTo... aliases were introduced as optimizations to the mapping process. So, instead of, Target.class, new ArrayList<Target>(collection.size())) one could simply use mapper.mapToArrayList(collection, Target.class). For some data types, like LinkedList, there is nothing that can be done to improve the performance. As a result, simple, Target.class, new LinkedList<Target>()) will do just fine.


Apache License, Version 2.0