Skip to content

Unmapped ghost collection properties #3425

@foaw

Description

@foaw

Expected behavior

MapStruct doesn't report properties that aren't backed by a real field, and no warnings about this are issued. If the unmapped target policy is ERROR, the code gets compiled.

Actual behavior

When mapping from type A to type B, if type B has a getter method that returns collections, MapStruct treats it as a property to be populated. If the unmapped target policy is ERROR, an error is raised respectively.

A "collection" is used here as a collective term for really more than just j.u.Collection. Here are the types I tested this with and which were marked unmapped: Collection (List, Set, Queue, Deque), Map, Stream. What's worth nothing is that Iterable, Iterator, and Optional are fine.

Since the others are probably tested for their collection-ness with a single helper method, it also may be worthwhile marking Iterable, Iterator and Optional as collection types too.

Steps to reproduce the problem

public static class Foo {
    List<String> values;
    public List<String> getValues() { return values; }
    public void setValues(List<String> values) { this.values = values; }
}

public static class Bar {
    List<String> values;

    public List<String> getValues() { return this.values; }
    public void setValues(List<String> values) { this.values = values; }

    // This is the root of the problem; try replacing with any non-collection type.
    public Stream<String> getX() {
        throw new UnsupportedOperationException();
    }
}

@Mapper
public interface BarMapper {
    @Mapping(target = "values", source = "values")
    Bar toBar(Foo foo);
}

MapStruct Version

1.5.5.Final

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions