Skip to content

Mapstruct try to map method from record #3146

@clemstoquart

Description

@clemstoquart

Expected behavior

Hi,

Let's say we have the following class:

public class User {
    private String name;
    // getter, setter,...
}

And we want to map it to the following record:

public record UserDto(String name) {
    public String prettyPrint() {
        System.out.println("Amazing user: " + name);
    }
} 

The following mapper should work:

@Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR)
public interface UserMapper {
    UserDto map(User user);
}

Actual behavior

But it doesn't.

Mapstruct reports an unmapped target property: prettyPrint which is wrong.

I think it should be safe to ignore methods for record while setters can't exist in a record.

What do you think ?

Steps to reproduce the problem

Any record with a method should trigger this issue.

MapStruct Version

1.5.3.Final

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions