Selma-错误的自定义字段到字段映射

时间:2020-10-13 20:32:02

标签: java mapping mapstruct

我有一个使用Mapstrcut的项目,我想用Selma替换它,因此在下面的示例中,我将AttachmentRequest映射到Attachment

public class Attachment {
    private SocialReason socialReason;
    public SocialReason getSocialReason() { return socialReason; }
    public Attachment socialReason(SocialReason socialReason) { this.socialReason = socialReason; return this; }
}

public class SocialReason {
    private String value;
    public String getValue() { return value; }
    public SocialReason value(String value) { this.value = value; return this; }
}

public class AttachmentRequest {
    private String socialReason;
    public String getSocialReason() { return socialReason; }
    public AttachmentRequest socialReason(String socialReason) { this.socialReason = socialReason; return this; }
}

我尝试使用下面的代码,但是出现此错误

不良的自定义字段到字段的映射:field out.getSocialReason()。value 来自目标bean的附件没有设置器! ->修复@Field({“” socialreason“,” socialreason.value“})

@Mapper(withIgnoreMissing = IgnoreMissing.ALL)
public interface AttachmentCommandMapper {
    @Maps(withCustomFields = { @Field({ "socialReason", "socialReason.value" }) })
    Attachment attachmentRequestToAttachment(AttachmentRequest attachmentRequest);
}

在Selma中,映射中的setter是必需的,因为在mapstruct中不需要setter。

0 个答案:

没有答案