Skip to content

Support conditional mapping for source parameters #2610

Description

@filiphr

With #2051 we added support for conditional mappings. Currently this only works for properties. However, it would be good to be able to apply the same logic for the source parameters.

e.g. If we have the following mapper

@Mapper
public interface CarMapper {

    CarDto map(Car car);

}

We currently generated something like:

public class CarMapperImpl implements CarMapper {

    public CarDto map(Car car) {
        if ( car == null ) {
            return null;
        }

        // perform mapping
    }
}

It would be good to be able to define a custom method that would tell is if the car should be mapped or not:

e.g. we could generate something like

public class CarMapperImpl implements CarMapper {

    public CarDto map(Car car) {
        if ( isCarPresent(car) ) {
            return null;
        }

        // perform mapping
    }
}

where isCarPresent is a method on the CarMapper. It can be a method that is available anywhere in the same discovery mechanism we have for the property conditional methods.

I believe that this issue is not super difficult to implement and would appreciate if someone from the community is interested in stepping up.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions