This is probably an easy one, but I cant find it in the docs. I have a person class
class BasicPerson {
private String name;
private int age;
private Date birthDate;
// getters/setters omitted
}
and a list of it
ArrayList<Person>
I want to change them to change them to
ArrayList<PersonDTO>
but with out an explicit loop. Is there a way to use MapperFacade.map for a list to list one line conversion ?
It has this functionality built-in. Did you tried using the method
List<D> ma.glasnost.orika.impl.ConfigurableMapper.mapAsList(Iterable<S> source, Class<D> destinationClass)
?
I tried to find a updated version of the Javadoc, but here is one of the 1.3.5. The current version is 1.4.5. MapperFacade Class
If you use the MapperFacade
interface, Orika can perform the mapping multiple times on the collection:
final MapperFacade mapperFacade = mapperFactory.getMapperFacade();
final List<Person> people = // Get the person instances
final List<PersonDto> personDtos = mapperFacade.mapAsList(people, PersonDto.class);
On the other hand, if you use the BoundMapperFacade
interface, it doesn't contain such a convenience method.
And lastly, if you choose to use the ConfigurableMapper
approach, it also includes a mapAsList
method which in fact delegates to the MapperFacade.mapAsList
method.
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