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?
ModelMapper, is an object-to-object framework that converts Java Beans (Pojos) from one representation to another. It automates different object mappings with a "convention follows configuration" approach allowing at the same time advanced functionality for cases with special needs.
The goal of ModelMapper is to make object mapping easy by automatically determining how one object model maps to another.
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.
Or with Java 8:
List<Target> targetList = sourceList .stream() .map(source -> modelMapper.map(source, Target.class)) .collect(Collectors.toList());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With