Context Based Mapping

Context based mapping can be specified by using the map-id attribute. Note that we also support nested context mapping by specifying a map-id at the field level.

<mapping map-id="caseA">
    <class-a>com.github.dozermapper.core.vo.context.ContextMapping</class-a>
    <class-b>com.github.dozermapper.core.vo.context.ContextMappingPrime</class-b>
    <field-exclude>
        <a>loanNo</a>
        <b>loanNo</b>
    </field-exclude>
    <field map-id="caseC">
        <a>contextList</a>
        <b>contextList</b>
        <b-hint>com.github.dozermapper.core.vo.context.ContextMappingNestedPrime
     </b-hint>
    </field>
</mapping>
<mapping map-id="caseB">
    <class-a>com.github.dozermapper.core.vo.context.ContextMapping</class-a>
    <class-b>com.github.dozermapper.core.vo.context.ContextMappingPrime</class-b>
</mapping>
<mapping map-id="caseC">
    <class-a>com.github.dozermapper.core.vo.context.ContextMappingNested</class-a>
    <class-b>com.github.dozermapper.core.vo.context.ContextMappingNestedPrime
  </class-b>
    <field-exclude>
        <a>loanNo</a>
        <b>loanNo</b>
    </field-exclude>
</mapping>
<mapping map-id="caseD">
    <class-a>com.github.dozermapper.core.vo.context.ContextMappingNested</class-a>
    <class-b>com.github.dozermapper.core.vo.context.ContextMappingNestedPrime
  </class-b>
</mapping>

To use a particular context when invoking the Mapper, you simply specify the map-id in your mapping call.

ContextMappingPrime cmpA = mapper.map(cm, ContextMappingPrime.class, "caseA");

results matching ""

    No results matching ""