tags:

views:

7

answers:

0

I'm having difficulties mapping a HashMap to a Pojo using dozer. Note: the attribute names in my Pojo don't map to the key values in HashMap i've populated. I'm trying to use the set-method attribute in the dozer mapping file to map the hash key to the Pojo setter. When I run the code below, I don't get any exceptions, but the the Pojo isn't populated with any data from the hash. Any suggestions or feedback would be appreciated.

Pojo:

public class Hotel {

private String companyAssignedId;

public Hotel(){}

public String getCompanyAssignedId() {
    return companyAssignedId;
}

public void setCompanyAssignedId(String companyAssignedId) {
    this.companyAssignedId = companyAssignedId;
}

}

Mapping XML:

<mapping>
   <class-a>com.reardencommerce.platformsvc.hadoop.dto.Hotel</class-a>
   <class-b>java.util.Map</class-b>

   <field>
        <a set-method="setCompanyAssignedId">hotel</a>
        <b key="COMPANY_ASSG_ID">rawData</b>
   </field>
</mapping>

Execution Code:

DozerBeanMapper beanMapper = new DozerBeanMapper();
List<String> mappingFiles = new ArrayList<String>();
mappingFiles.add("dozer-test.xml");
beanMapper.setMappingFiles(mappingFiles);
Map<String, String> rawData = new HashMap <String, String> ();
rawData.put("COMPANY_ASSG_ID","12345");
Hotel hotel = new Hotel();
beanMapper.map(rawData, hotel);