title: ModelMapper map one object into three
body: <p>In my Java project I am using ModelMapper for mapping from <code>entity</code> object into <code>DTO</code> object. </p>
  
  <p>My entity have inside object <code>hierarchy</code> that has three Long properties.
  My DTO object has only one Long properties, so I created custom map to map between them.</p>
  
  <pre><code>public class MyMap extends PropertyMap&lt;DTO, Entity&gt; {
  
    /**
     * Main function that is called when mapping objects.
     */
    @Override
    protected void configure() {
  
      final Converter&lt;Long, Hierarchy&gt; hierarchyToId = context -&gt; {
  
        if (context.getSource() != null) {
  
          final Long Id = context.getSource();
  
          final HierarchyDto dto = calculateHierarchy(Id)
  
          // map dto to entity.
          final Hierarchy hierarchy = new Hierarchy();
          hierarchy.setFirstId(dto.getFirstId());
          hierarchy.setSecondId(dto.getSecondId());
          hierarchy.setThirdId(dto.getThirdId());
  
          return hierarchy;
        }
  
        return null;
       };
  
      // map objects.
      this.using(hierarchyToId).map(this.source.getId(), this.destination.getHierarchy());
    }
  </code></pre>
  
  <p>}</p>
  
  <p>This give me an error :</p>
  
  <pre><code>java.lang.NullPointerException: null ...
  
  ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.modelmapper.ConfigurationException: ModelMapper configuration errors:
  1) The destination property com....DTO.setId() matches multiple source property hierarchies:
  
  com....getHierarchy()/com....getFirstId()
  com....getHierarchy()/com....getSecondId()
  com....getHierarchy()/com....getThirdId()
  
  1 error] with root cause
  org.modelmapper.ConfigurationException: ModelMapper configuration errors:
  </code></pre>
  
  <p>I understand that Mapper has problems that I map one object into 3 but what do I need to do that it will work.</p>