duns
duns

Reputation: 93

Mapstruct conversion List of abstract entity to dtos

I have to map a list of abstract entity with mapstruct, but I don't have any idea how to do it, because I have the following error message:

No implementation can be generated for this method. Found no method nor implicit conversion for mapping source element type into target element type.

public class AbstractArea {
    private List<AbstractArea> areas;

    public List<AbstractArea> getAreas() {
        return areas;
    }

    public void setAreas(List<AbstractArea> areas) {
        this.areas = areas;
    }
}

@Mapper()
public interface AbstractAreaMapper {
    ...
    List<AbstractAreaDto> abstractAreasToAbstractAreaDtos(List<AbstractArea> areaList);
}

Upvotes: 2

Views: 3242

Answers (1)

Gunnar
Gunnar

Reputation: 19040

You need to declare a mapping method which converts the element type of the list, i.e.:

AbstractAreaDto abstractAreaToDto(AbstractArea area);

The implementation generated for abstractAreasToAbstractAreaDtos will invoke this method for each element of the source list.

That said, you'd likely need more specific mapping methods for the sub-types in your hierarchies rather than the abstract base types.

Upvotes: 7

Related Questions