mapstruct / mapstruct/mapstruct
Decorator not working with object references
還沒有人認領這個 Issue。
- 主要語言
- Java
- 星號
- 7.7k
- 分支
- 1.1k
- PR 合併指標
- 30 天內沒有已合併 PR
描述
Hi,
I want to user spring decorator for reference object.
It is a bug or I have something wrong in my code but problem is that when using decorator for Dto generated code call base mapping method (InspectionResultMapper2.tireToTireDto2(tire) instead my decorated method (InspectionResultMapperDecorator2.tireToTireDto2).
Example dto and model with problem
public class InspectionDto2 {
private Long id;
private TireDto2 tire;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public TireDto2 getTire() {
return tire;
}
public void setTire(TireDto2 tire) {
this.tire = tire;
}
}
public class TireDto2 {
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
Model:
public class Inspection implements Serializable {
private Tire tire;
public Tire getTire() {
return tire;
}
public void setTire(Tire tire) {
this.tire = tire;
}
}
public class Tire implements Serializable {
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
Mapping condig:
@Mapper(componentModel = "spring")
@DecoratedWith(InspectionResultMapperDecorator2.class)
public interface InspectionResultMapper2 {
InspectionDto2 InspectionToInspectionDto2(Inspection inspection);
TireDto2 tireToTireDto2(Tire tire);
}
public abstract class InspectionResultMapperDecorator2 implements InspectionResultMapper2 {
@Autowired
@Qualifier("delegate")
private InspectionResultMapper2 delegate;
@Override
public TireDto2 tireToTireDto2(Tire tire) {
//TireDto tireDto = delegate.tireToTireDto(tire);
TireDto2 tireDto = new TireDto2();
tireDto.setId(222L);
return tireDto;
}
}
Generated code is:
@Component
@Qualifier("delegate")
public class InspectionResultMapper2Impl_ implements InspectionResultMapper2 {
@Override
public InspectionDto2 InspectionToInspectionDto2(Inspection inspection) {
if ( inspection == null ) {
return null;
}
InspectionDto2 inspectionDto2 = new InspectionDto2();
inspectionDto2.setId( inspection.getId() );
/* HERE CALL UNDECORADER METHOD from InspectionResultMapper2 */
inspectionDto2.setTire( tireToTireDto2( inspection.getTire()) );
return inspectionDto2;
}
@Override
public TireDto2 tireToTireDto2(Tire tire) {
if ( tire == null ) {
return null;
}
TireDto2 tireDto2_ = new TireDto2();
tireDto2_.setId( tire.getId() );
return tireDto2_;
}
}
When I map Inspection with method "InspectionResultMapper2.inspectionToInspectionDto2" my decorator is not called. In generated code mapper call base method (see comment).
It is possible to use decorator for reference object ?
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從報告中顯示的產生的 InspectionResultMapper2Impl_ 以及 InspectionResultMapper2/InspectionResultMapperDecorator2 的映射宣告開始。重現 Inspection-to-InspectionDto2 映射,並追蹤巢狀輪胎映射的選取方式;完成的條件是巢狀呼叫能夠到達經過裝飾的 tireToTireDto2 方法,且該行為由回歸測試涵蓋。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- java, spring
- 領域
- tooling
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100