カスタムマッピングにより、ソースフィールドをターゲットフィールドにマップするために独自のロジックを定義できます。 これらは Dozer の顧客コンバーターと機能的に似ており、以下の 2 つの大きな違いがあります。
カスタムマッピングは、マッピング設定で組み込みの '_customMapping' コンバーターを使用して宣言されます。 このコンバーターのパラメーターの構文は以下のとおりです。
[class-name][,method-name]
[class-name][,method-name]
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
メソッド名はオプションです。Dozer コンポーネントは、マッピングに必要な入出力タイプに一致するメソッドを検索します。 カスタムマッピングと設定の例を以下に示します。
public class CustomMapper {
// All customer ids must be wrapped in "[ ]"
public Object mapCustomer(String customerId) {
return "[" + customerId + "]";
}
}
public class CustomMapper {
// All customer ids must be wrapped in "[ ]"
public Object mapCustomer(String customerId) {
return "[" + customerId + "]";
}
}
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
<mappings xmlns="http://dozermapper.github.io/schema/bean-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://dozermapper.github.io/schema/bean-mapping http://dozermapper.github.io/schema/bean-mapping.xsd">
<mapping>
<class-a>org.example.A</class-a>
<class-b>org.example.B</class-b>
<field custom-converter-id="_customMapping"
custom-converter-param="org.example.CustomMapper,mapCustomer">
<a>header.customerNum</a>
<b>custId</b>
</field>
</mapping>
</mappings>
<mappings xmlns="http://dozermapper.github.io/schema/bean-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://dozermapper.github.io/schema/bean-mapping http://dozermapper.github.io/schema/bean-mapping.xsd">
<mapping>
<class-a>org.example.A</class-a>
<class-b>org.example.B</class-b>
<field custom-converter-id="_customMapping"
custom-converter-param="org.example.CustomMapper,mapCustomer">
<a>header.customerNum</a>
<b>custId</b>
</field>
</mapping>
</mappings>
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow