java - MapStruct无法在mapper函数中映射基类中的字段

时间:2018-01-29 16:45:39

标签: java mapstruct

我有一个Base dto和一个扩展它的dto

public abstract class AbstractItem {
    private String upc;
    private String quantity;

    //getter and setter for upc and quantity
}

public class OrderedItem extends AbstractItem {
    private String orderId;

    // getter and setter for orderId
}

然后我有一个我想从OrderedItem转换的模态。此模态扩展了基本模态

public abstract class AbstractModal {
    private String qty;

    public void setQty(String qty) {
        this.qty = qty;
    }
    public String getQty() {
        return qty;
    }
}

public class ItemModal extends AbstractModal {
    private String orderNbr;
    private String upcNbr;

    // getter and setter for orderNbr and upcNbr;
}

这是我使用Mapstruct的mapper函数

@Mapper
public interface DtoMapper {

    @Mappings({
        @Mapping(source = "orderedItem.orderId" target = "orderNbr"),
        @Mapping(source = "orderedItem.upc" target = "upcNbr"),
        @Mapping(source = "orderedItem.quantity" target = "qty")
    })
    ItemModal convert(OrderedItem orderedItem);
}

在编译过程中,我收到错误Unknown property "qty" in result type test.modal.ItemModal.

Mapstruct是否支持基类的映射字段? 如果是,请告诉我我的代码有什么问题? 我正在使用java 8和mapstruct 1.2.0

修改:在qty

中为AbstractModal添加了getter和setter

0 个答案:

没有答案