title: Mapping between two objects that contain a List using Orika
body: <p>I am trying to use Orika to map between two objects that contain a <code>List&lt;...&gt;</code> where the List type is another object, however despite trying various permutations of the mapping configuration in <code>mapperFactory.classMap(...)</code> Orika throws an exception when I run my program.</p>
  
  <p>Looking at <a href="http://orika-mapper.github.io/orika-docs/mappings-via-classmapbuilder.html" rel="noreferrer">http://orika-mapper.github.io/orika-docs/mappings-via-classmapbuilder.html</a> it seems to suggest that that syntax for mapping a <code>List</code> should be <code>parentProperty{childProperty}</code>.</p>
  
  <p>For the purposes of this question I've simplified the objects that I'm trying to map. The source object is <code>ToDoTaskListEntity</code> and the destination object is <code>ToDoTaskListDTO</code>. The source object <code>ToDoItemEntity</code> contains a List which is defined as <code>List&lt;ToDoItemEntity&gt;</code> and the destination object contains a corresponding List which is defined as <code>List&lt;ToDoItemDTO&gt;</code></p>
  
  <p><strong>My question is</strong> how should I define the mapping configuration in Orika between <code>ToDoTaskListEntity</code> and <code>ToDoTaskListDTO</code> so that the child object <code>List&lt;ToDoItemEntity&gt;</code> is also mapped to <code>List&lt;ToDoItemDTO&gt;</code> within their respective parent objects?</p>
  
  <hr>
  
  <p>The code for my mapping configuration is as follows: </p>
  
  <pre><code>MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
  
  mapperFactory.classMap(ToDoItemEntity.class, ToDoItemDTO.class)
      .field("id", "id")
      .field("description", "description")
      .field("status", "status")
      .byDefault()
      .register();
  
  mapperFactory.classMap(ToDoTaskListEntity.class, ToDoTaskListDTO.class)
      .field("listName", "listName")
      .field("toDoItems{id}", "toDoItems{id}")
      .field("toDoItems{description}", "toDoItems{description}")
      .field("toDoItems{status}", "toDoItems{status}")
      .byDefault()
      .register();
  </code></pre>
  
  <p>The code for invoking the mapping is as follows:</p>
  
  <pre><code>MapperFacade mapper = mapperFactory.getMapperFacade();
  ToDoTaskListDTO toDoTaskListDTO = mapper.map(toDoTaskListEntity, ToDoTaskListDTO.class);
  </code></pre>
  
  <p>The code for my source objects is as follow:</p>
  
  <pre><code>public class ToDoTaskListEntity {
  
      private String ListName;
      private List&lt;ToDoItemEntity&gt; toDoItems;
  
      // Getters and setters
  }
  
  public class ToDoItemEntity {
  
      private int id;
      private String description;
      private Status status;
  
      // Getters and setters
  }
  </code></pre>
  
  <p>The code for my destination objects is as follow:</p>
  
  <pre><code>public class ToDoTaskListDTO {
  
      private String listName;
      private List&lt;ToDoItemDTO&gt; toDoItems;
  
      public ToDoTaskListDTO(String listName, List&lt;ToDoItemDTO&gt; toDoItems) {
          this.listName = listName;
          this.toDoItems = toDoItems;
      }
  
      //Getters but no setters
  
  }
  
  public class ToDoItemDTO {
  
      private int id;
      private String description;
      private Status status;
  
      public ToDoItemDTO(int id, String description, Status status) {
          this.id = id;
          this.description = description;
          this.status = status;
      }
  
      // Getters but no setters
  }
  </code></pre>
  
  <p>The exception that thrown by Orika is as follow:</p>
  
  <pre><code>Exception in thread "main" ma.glasnost.orika.MappingException: exception while creating object factory for test.orikademo.ToDoTaskListDTO
  -----begin dump of current state-----------------------------
  Registered object factories: 1 (approximate size: 25.4 kB)
    [ToDoTaskListDTO] : {}
  -------------------------------------------------------------
  Registered mappers: 2 (approximate size: 961.5 kB)
    [0] : GeneratedMapper&lt;ToDoItemEntity, ToDoItemDTO&gt; {usedConverters: [], usedMappers: [], usedMapperFacades: [], usedTypes: [] }
    [1] : GeneratedMapper&lt;ToDoTaskListEntity, ToDoTaskListDTO&gt; {usedConverters: [], usedMappers: [], usedMapperFacades: [DefaultBoundMapperFacade&lt;ToDoItemEntity, ToDoItemDTO&gt;], usedTypes: [List&lt;ToDoItemEntity&gt;, List&lt;ToDoItemDTO&gt;] }
  -------------------------------------------------------------
  Registered concrete types: 5 (approximate size: 122.4 kB)
    [interface java.util.List] : ArrayList&lt;Object&gt;
    [interface java.util.Set] : LinkedHashSet&lt;Object&gt;
    [interface java.util.Collection] : ArrayList&lt;Object&gt;
    [interface java.util.Map$Entry] : MapEntry&lt;Object, Object&gt;
    [interface java.util.Map] : LinkedHashMap&lt;Object, Object&gt;
  -------------------------------------------------------------
  Resolved strategies: 0 (approximate size: 0.8 kB)
  -------------------------------------------------------------
  Unenhance strategy: ma.glasnost.orika.unenhance.BaseUnenhancer@292a74d5
  -----end dump of current state-------------------------------
      at ma.glasnost.orika.impl.generator.ObjectFactoryGenerator.build(ObjectFactoryGenerator.java:110)
      at ma.glasnost.orika.impl.DefaultMapperFactory.lookupObjectFactory(DefaultMapperFactory.java:1005)
      at ma.glasnost.orika.impl.DefaultMapperFactory.lookupObjectFactory(DefaultMapperFactory.java:925)
      at ma.glasnost.orika.impl.MapperFacadeImpl.resolveMappingStrategy(MapperFacadeImpl.java:218)
      at ma.glasnost.orika.impl.MapperFacadeImpl.map(MapperFacadeImpl.java:734)
      at ma.glasnost.orika.impl.MapperFacadeImpl.map(MapperFacadeImpl.java:714)
      at test.orikademo.App.main(App.java:54)
  Caused by: java.lang.NullPointerException
      at ma.glasnost.orika.impl.generator.ObjectFactoryGenerator.addSourceClassConstructor(ObjectFactoryGenerator.java:173)
      at ma.glasnost.orika.impl.generator.ObjectFactoryGenerator.addCreateMethod(ObjectFactoryGenerator.java:124)
      at ma.glasnost.orika.impl.generator.ObjectFactoryGenerator.build(ObjectFactoryGenerator.java:95)
      ... 6 more
  </code></pre>