mapstruct / mapstruct-idea

An IntelliJ IDEA plugin for working with MapStruct
Other
136 stars 38 forks source link

Unmapped target properties warning is missing if source is a Java record #160

Closed aleksvidak closed 10 months ago

aleksvidak commented 10 months ago

When mapping from a DTO that is a Java record to entity class, Intellij does not show warning when there are unmapped properties.

@Mapper(componentModel = "spring")
public interface UserMapper {

  User toEntity(UserDto dto); // this one will not be reported as warning if there are unmapped properties

  UserDto toDto(User entity);
}

During mvn compile, warnings are correctly shown in the console.

Mapstruct version: 1.6.1 Intellij version: 2023.2.5

thunderhook commented 10 months ago

Hi @aleksvidak

Thank you for the report. I cannot reproduce this. The following sample generates warnings for me (does not matter if mapped from a record or a class):

import org.mapstruct.Mapper;

@Mapper
interface UserRecordMapper {

    UserDto mapFromRecord(UserRecord user);

    UserDto mapFromClass(UserClass user);

}

record UserRecord(String username, String password) { }

record UserDto(String name, String pw) { }

class UserClass {
    public String username;
    public String password;
}

Would you be so kind and post your code of User and UserDto?

aleksvidak commented 10 months ago

The case is when mapping from record to class.

public record UserDto(String test, String test4) implements Serializable {}

@SuperBuilder(toBuilder = true)
@Getter
@Setter
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class User {

  private String test;

  private String test2;

  private String test3;
}

import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;

@Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
public interface UserMapper {

  User toEntity(UserDto userDto);

  UserDto toDto(User user);
}
thunderhook commented 10 months ago

When removing the @SuperBuilder from the target object, then the warnings are shown for me. Can you tell me if this is the case in your code? If yes, then it is due to #159

aleksvidak commented 10 months ago

When removing the @SuperBuilder from the target object, then the warnings are shown for me. Can you tell me if this is the case in your code? If yes, then it is due to #159

Yes, when I remove @SuperBuilder, warnings are back.

thunderhook commented 10 months ago

Perfect, will be fixed soon in #159. 👍