mapstruct / mapstruct/mapstruct

@InheritConfiguration and @BeanMapping: ignoreUnmappedSourceProperties are not "merged" as expected

オープン
#2,092 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

up-for-grabs
主要言語
Java
スター
7.7k
フォーク
1.1k
PR マージ指標
30日以内にマージされた PR はありません

説明

First of all: mapstruct is awesome! I use it to map a really complex hibernate domain model to simple DTOs and vice versa - works great!

I work with a strict MapperConfig regarding source and target properties to catch future changes in the domain model:

@MapperConfig(
        unmappedSourcePolicy = ReportingPolicy.ERROR,
        unmappedTargetPolicy = ReportingPolicy.ERROR
)
public interface CentralConfig {}

For this reason, I have to work with @BeanMapping(ignoreUnmappedSourceProperties = {...}) a lot. Unfortunately this does not work well if @InheritConfiguration is used: The second method mapB "forgets" that the source property "a2" should be ignored, as defined for the first method mapA which configuration is inherited by mapB.

Am I doing something wrong or am I expecting something that does not (yet) work?

@Mapper(
        config = CentralConfig.class
)
public interface MyMapper {

    @Mapping(source = "a1", target = "aa1")
    @BeanMapping(ignoreUnmappedSourceProperties = {"a2"})
    TargetBeanA mapA(BeanA beanA);

    @InheritConfiguration
    @Mapping(source = "b1", target = "bb1") // inheritance works as expected
    @BeanMapping(ignoreUnmappedSourceProperties = {"b2"}) // compiler error: Unmapped source property: "a2"
    TargetBeanB mapB(BeanB beanB);
}

Below all the beans:

@Getter
@Setter
public class BeanA {
    
    private int a1;
    private int a2;
}
@Getter
@Setter
public class BeanB extends BeanA {

    private int b1;
    private int b2;
}
@Getter
@Setter
public class TargetBeanA {
    
    private int aa1;
}
@Getter
@Setter
public class TargetBeanB extends TargetBeanA {
    
    private int bb1;
}

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、継承されたマッピングメソッドに対して @InheritConfiguration と @BeanMapping がどのように処理されるかを追跡します。BeanA/BeanB と TargetBeanA/TargetBeanB の例で動作を検証してください。継承された a2 ignore とローカルの b2 ignore の両方が適用され、unmapped-source エラーが発生しないことを確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
java
領域
devtools
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。