Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link

Description

@zyberzebra
Issue body actions

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

Reactions are currently unavailable

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

Morty Proxy This is a proxified and sanitized view of the page, visit original site.