Skip to content

Inverse Inheritance Strategy not working for ignored mappings only with target #3652

Description

@zyberzebra

Expected behavior

Inverse Configuration is autmatically generated.

Actual behavior

@Mappings have to be defined twice

Steps to reproduce the problem

Setup

@Mapper(config = FooBarConfig.class)
public interface FooBarMapper {

    Bar toBar(Foo foo);

    Foo toFoo(Bar bar);

}
@Data
class Foo { int secret; }
@Data
class Bar { int secret; }

@MapperConfig(mappingInheritanceStrategy = MappingInheritanceStrategy.AUTO_INHERIT_ALL_FROM_CONFIG)
interface FooBarConfig {

    @Mapping(target = "secret", ignore = true)
    Bar toBar(Foo foo);

    @InheritInverseConfiguration(name = "toBar")
    Foo toFoo(Bar bar);
}

Generated

public class FooBarMapperImpl implements FooBarMapper {

    @Override
    public Bar toBar(Foo foo) {
        if ( foo == null ) {
            return null;
        }

        Bar bar = new Bar();

        return bar;
    }

    @Override
    public Foo toFoo(Bar bar) {
        if ( bar == null ) {
            return null;
        }

        Foo foo = new Foo();

        foo.setSecret( bar.getSecret() );

        return foo;
    }
}

Only way to get it working

@MapperConfig(mappingInheritanceStrategy = MappingInheritanceStrategy.AUTO_INHERIT_FROM_CONFIG)
interface FooBarConfig {
    @Mapping(target = "secret", ignore = true)
    Bar toBar(Foo foo);
    @Mapping(target = "secret", ignore = true)
    Foo toFoo(Bar bar);
}

MapStruct Version

1.5.5

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions