mapstruct-idea icon indicating copy to clipboard operation
mapstruct-idea copied to clipboard

Incorrect "unmapped property" warning with inheritance

Open jacobhampel opened this issue 6 years ago • 2 comments

We have some internal messages which extend a BaseClass. This BaseClass contains some variables for our database. These variables should be present in our DTOs. To avoid ignoring the variables in every single mapper we're using a GenericConfig. In the GenericConfig no warnings were displayed. Neither when we compile the code nor at the IDE level. Our GenericConfig looks like the following:

@MapperConfig(uses = DateToOffsetDateMapper.class,
        unmappedTargetPolicy = ReportingPolicy.ERROR,
        mappingInheritanceStrategy = MappingInheritanceStrategy.AUTO_INHERIT_FROM_CONFIG)
public interface GenericConfig {

    @Mapping(target = "storageId", ignore = true)
    @Mapping(target = "date", ignore = true)
    BaseClass genericMessageMapping(GenericDto dto); 
}

The GenericDto is an empty interface. All DTOs implements this interface.

The BaseClass looks like the following:

public class BaseClass
{
   private String storageId;
   private OffsetDateTime date;

   //getter and setter
}

Every mapper extends this config.

@Mapper(config = GenericConfig.class, uses = {})
public interface CarMapper  {
   Car map(CarDto dto);
}

In this example Car extends BaseClass and CarDto extends GenericDto. Now my question: Why does the IDEA plugin shows me the error that I have unmapped properties at Car map(CarDto dto)? If I compile the code no warnings are shown, which I think is correct.

Maybe you have an idea where I have to look.

jacobhampel avatar Aug 01 '19 15:08 jacobhampel

Currently we are not looking into the Mapper#config nor we apply inheritance for the mapping policies.

Edit: I didn't see that this issue is inthe correct place

filiphr avatar Aug 02 '19 16:08 filiphr

@jacobhampel if you are interested in adding this functionality to the plugin I can help you out

filiphr avatar Aug 02 '19 16:08 filiphr