Skip to content

Inheriting mapping definition #3611

@twallmey

Description

@twallmey

Expected behavior

Hi all,
I've got a set of classes that (not directly) extend a common base class (XKBObject). For each class of this set I've defined a mapper. During mapping I would like to exclude a single property ("type") from the base class within all mappers.

For this reason I've defined a central MappeConfig that should exclude this single property:

@MapperConfig(
        componentModel = "spring",
        //build should fail if a target property is not mapped - in this case the mapping has to be defined manually
        unmappedTargetPolicy = ReportingPolicy.ERROR,
        mappingInheritanceStrategy = MappingInheritanceStrategy.AUTO_INHERIT_ALL_FROM_CONFIG
)
public interface MapstructConfig {
    @Mapping(target = "type", ignore = true)
        //for test purpose only
    XKBObject convert(XKBObject dto);
}

The configuration is referenced within all mappers:

@Mapper(
        config = MapstructConfig.class,
        componentModel = MappingConstants.ComponentModel.DEFAULT
)

I would expect that the mentioned "type"-Attribute is excluded from mapping.

Actual behavior

Unfortunately the property (type) is not excluded. Do you have any hints?

Steps to reproduce the problem

@MapperConfig(
        componentModel = "spring",
        //build should fail if a target property is not mapped - in this case the mapping has to be defined manually
        unmappedTargetPolicy = ReportingPolicy.ERROR,
        mappingInheritanceStrategy = MappingInheritanceStrategy.AUTO_INHERIT_ALL_FROM_CONFIG
)

MapStruct Version

1.5.5.Final

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions