Skip to content

Improve / fix ignoreUnmappedSourceProperties handling of multiple arguments #2562

@incaseoftrouble

Description

@incaseoftrouble

When mapping multiple arguments, one needs to specify the bean name of the property, i.e. argument.property (see here). However, ignoreUnmappedSourceProperties doesn't require this, and matches only based on name (even if there are ambiguities!). This is a bit inconsistent and should be fixed. In particular, the following goes through:

@Mapper(unmappedSourcePolicy = ReportingPolicy.ERROR,
        unmappedTargetPolicy = ReportingPolicy.ERROR)
public abstract class MapperTest {
  public static class Foo {
    public int foo;
    public int bar;
  }

  public static class Bar {
    public int foo;
    public int bar;
  }

  @Mapping(target = "bar", source = "bar")
  @BeanMapping(ignoreUnmappedSourceProperties = "bar")
  abstract Bar create(Foo foo, int bar);
}

even though foo.bar is not mapped (result.bar = bar is generated)
Note that (this might be a separate issue) if the @Mapping is removed, i.e.

  @BeanMapping(ignoreUnmappedSourceProperties = "bar")
  abstract Bar create(Foo foo, int bar);

instead result.bar = foo.bar is generated. In my opinion, this should raise an ambiguitiy. If you refractor Foo and rename the bar field, mapping will silently change to the second argument instead. This is really easy to miss (especially if you don't have warnings for unmapped source properties).

Moreover, it might be useful to have wildcard capabilities on ignoreUnmappedSourceProperties. So argument.* for example would mean "ignore all unmapped properties of argument", and "*" means ignore all.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions