I am using ModelMapper Framework (http://modelmapper.org/) for mapping objects in Java. I have encountered a problem while mapping concrete classes (DTO to Entites) containing abstract classes.
Example:
Task has a list of AbstractItems.
AbstractItems are Question and Criteria.
public class TaskDTO {
...
private List<AbstractItemDTO> items;
}
Mapping method:
// task is an TaskDTO object
return getModelMapper().map(task, TaskEntity.class);
ModelMapper tries to create a new instance of AbstractItem, which throws an exception.
Is there a way to map the abstract classes during the runtime?
Like QuestionDTO -> Question, CriteriaDTO ->Criteria