Does ModelMapper library support collections like ArrayList or HashSet?

Ray picture Ray · Aug 26, 2011 · Viewed 28.8k times · Source

This question is not relating with AutoMapper. My question is about ModelMapper in java, however I cannot create new tag for modelmapper as my little reputation. Sorry for confusion.

Anyway, my question is that does modelmapper library support collections like arraylist or hashset? it seems not support collection to collection mapping. Is it true?

Answer

José picture José · Jul 29, 2013

You can also map collections () directly:

    List<Person> persons = getPersons();
    // Define the target type
    java.lang.reflect.Type targetListType = new TypeToken<List<PersonDTO>>() {}.getType();
    List<PersonDTO> personDTOs = mapper.map(persons, targetListType);

Documentation on mapping Generics.