I have come across a situation where my mapping method has 3 parameters, and all the three are being used in deriving one of the properties of the target type.
I have created a default mapping method in the interface keeping the logic for deriving the property, now for calling this method, I could use an expression = "java( /*method call here*/ )"
in the @Mapping
annotation.
Is there any way to do this with any of the mapstruct annotation like @qualifiedByName
, I tried commenting the annotation having expression property and used qualifiedByName, but it doesn't work :
@Mapper
public interface OneMapper {
@Mapping(target="id", source="one.id")
//@Mapping(target="qualified",expression = "java( checkQualified (one, projId, code) )")
@Mapping(target="qualified",qualifiedByName="checkQualifiedNamed")
OneDto createOne (One one, Integer projId, Integer val, String code);
@Named("checkQualifiedNamed")
default Boolean checkQualified (One one, Integer projId, Integer val, String code) {
if(one.getProjectId() == projId && one.getVal() == val && one.getCode().equalsIgnoreCase(code)) {
return Boolean.TRUE;
}
return Boolean.FALSE;
}
}