I have a simple class that I want to map to a DTO class using modelMapper.
class Source {
private String name;
private String address;
List<Thing> things;
// getters and setters follows
}
class Thing {
private String thingCode;
private String thingDescription;
// getters and setters
}
and I want to convert these to a sourceDTO that contains a list of ThingDTOs, for example
class sourceDTO {
private String name;
private String address;
List<ThingDTO> things;
// getters and setters.
}
class ThingDTO {
private String thingCode;
private String thingDescription;
// getters and setters
}
If I drop my list of Things and list of ThingsDTO then modelmapper is a delight to use,
modelMapper.map(source, SourceDTO.class);
But I can't work out how to get the mapper to convert the List of Things to List of ThingDTOs. From the documentation, I think I need to create a mapper class that extends PropertyMap but I can't work out how to configure it.
Any pointers to the relevant documentation would be welcome