Dozer Sample

Configurable dozer converter:
public class BalanceConverter implements ConfigurableCustomConverter {

    public Object convert(Object destinationFieldValue, Object sourceFieldValue,
            Class destinationClass, Class sourceClass, String param) {

        Balance[] source = (Balance[]) sourceFieldValue;
        //BigDecimal destination = (BigDecimal) destinationFieldValue;
        
        for (Balance balance : source) {
            if (param.equals(balance.getBalanceId())) {
                return balance.getBalance();
            }
        }
        
        return null;
    }
}

      <field custom-converter="customConverters[0]"
           custom-converter-param="CUR">
        <a>balances</a>
        <b>currentBalance</b>
      </field>

<bean id="mapper" class="org.dozer.DozerBeanMapper">
  <property name="mappingFiles">
    <list>
      <value>account-mappint.xml</value>           
    </list>
  </property>
 <property name="customConvertersWithId"> 
      <map> 
             <entry key="balanceConverter">
                  <ref bean="balanceConverter"/>
            </entry>
      </map> 
    </property>   
</bean> 


你可能感兴趣的:(java,xml)