MapStruct未定义方法调用

问题描述

我有一个给定的情况,如下所示

class Curve {
      private List<Point> points = new ArrayList<>();

      public List<Point> getPoint() {
       this.points;
      }
      
      public void addPoint(Point point) {
       this.point.add(point);
      }
  }

mapper类如下:

@Mapper
public interface CurveMapper {

CurveMapper INSTANCE = Mappers.getMapper(CurveMapper.class);

com.entity.Curve mapTo(com.dto.Curve);

}

MapStruct会自动生成CurveMapperImpl类,如下所示:

public class CurveMapperImpl implements CurveMapper {
       
@Override
public com.entity.Curve mapTo(com.dto.Curve curve) {    
     if (curve == null) {
       return null;
     }

     com.entity.Curve curve1 = new com.entity.Curve();
     for(com.dto.Point point : curve) {
        curve1.add(convertPoint(point));
     } 
}

mapStruct默认情况下会查找 curve.add() 方法,但是目标类具有 curve.addPoint() 。因此失败了。

由于无法修改目标类结构,我如何要求mapStruct查找 curve.addPoint()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)