Skip to content

@Condition cannot be used only with @Context parameters #3561

@filiphr

Description

@filiphr

Expected behavior

I would expect that when a condition only has @Context parameters that it is picked up and used if it is applicable

Actual behavior

The @Condition method is not picked

Steps to reproduce the problem

@Mapper
public interface TestMapper {

    @Mapping(target = "value", conditionQualifiedByName = "shouldMapValue")
    Target map(Source source);

    @Condition
    @Named("shouldMapValue")
    default boolean shouldMapValue(@Context boolean shouldMapValue) {
        return shouldMapValue;
    }
    class Target {

        private final String value;

        public Target(String value) {
            this.value = value;
        }

        public String getValue() {
            return value;
        }
    }

    class Source {

        private String value;
        private boolean valueInitialized;

        public String getValue() {
            if (valueInitialized) {
                return value;
            }

            throw new IllegalStateException("value is not initialized");
        }

        public void setValue(String value) {
            this.valueInitialized = true;
            this.value = value;
        }
    }
}

MapStruct Version

1.5.5.Final

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions