Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static factory method incorrectly recognized as a fluent setter #1660

Closed
bgK opened this issue Nov 30, 2018 · 2 comments
Closed

Static factory method incorrectly recognized as a fluent setter #1660

bgK opened this issue Nov 30, 2018 · 2 comments
Labels
Milestone

Comments

@bgK
Copy link

bgK commented Nov 30, 2018

When using mapstruct 1.3.0.Beta2 with unmappedTargetPolicy = ReportingPolicy.ERROR target classes with a static one parameter factory method fail the build with the error: Unmapped target property: "of".

Example target class

package test;

public class Car {
    private String data;

    public static Car of(String data) {
        Car car = new Car();
        car.setData(data);
        return car;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }
}

Example source class

package test;

public class Car2 {
    private String data;

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }
}

Example mapper

package test;

import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;

@Mapper(unmappedTargetPolicy = ReportingPolicy.ERROR)
public interface CarMapper {
    Car toCar(Car2 car2);
}

Expected result

The mapper is generated without error, and without adding configuration to ignore the static factory method.

Perhaps static methods should not be considered as fluent setters?

@filiphr filiphr added this to the 1.3.0.x milestone Dec 1, 2018
@filiphr filiphr added the bug label Dec 1, 2018
@filiphr
Copy link
Member

filiphr commented Dec 1, 2018

Indeed static methods should not be considered as fluent setters

filiphr added a commit to filiphr/mapstruct that referenced this issue Dec 1, 2018
…ssible getter, setter, presence check and / or adder methods
filiphr added a commit that referenced this issue Dec 1, 2018
…tter, setter, presence check and / or adder methods
@filiphr
Copy link
Member

filiphr commented Dec 1, 2018

Thanks for spotting this @bgK it was not just for fluent setters we were actually considering all public methods. We have now changed this and only public not static methods can be candidates for getters / setters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants