Skip to content

Mapstruct ignores the generic bounds when using explicit mappings #2947

@bgK

Description

@bgK

Given a generic source class with a member implementing an interface,

public interface TestInterface {}

public record TestEntity<T extends TestInterface>(T data) {}

A target class,

public record TestDto(String data) {}

And a mapper,

@Mapper
public abstract class TestMapper {
    @Mapping(target = "data", source = "data") // Removing this works around the issue
    public abstract TestDto map(TestEntity<?> action);

    String mapToString(TestInterface rawData) {
        return rawData.toString();
    }
}

When compiling with Mapstruct 1.5.2, the following error occurs: TestMapper.java:[12,5] Can't map property "Object data" to "String data". Consider to declare/implement a mapping method: "String map(Object value)"..

Note that removing the explicit mapping @Mapping(target = "data", source = "data") works around the issue (Obviously not possible in more complex situations).

This used to work with Mapstruct 1.4.1.

This is the reproduction case packaged as a Maven project:
mapstruct-generic-bounds.zip

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions