org.dozer.MappingException: error

5k views Asked by At

i have two pojo class which contain same field private String nameId;

my dozermapping.xml file contain

<mappings xmlns="http://dozer.sourceforge.net"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://dozer.sourceforge.net                               http://dozer.sourceforge.net/schema/beanmapping.xsd">
      <mapping map-id="a"> 
    <class-a>com.ihx.util.Fileobject</class-a>
    <class-b>com.ihx.model.Test</class-b>   
    <field>
    <a>nameId</a>
    <b>nameId</b>
    </field> 
  </mapping>  
  </mappings>

i m getting an error which is given below

org.dozer.MappingException Property 'nameId' not found in Class: class java.lang.String`

my code contain contain

 List myMappingFiles = new ArrayList();
                 myMappingFiles.add("dozerMapping.xml");
                // myMappingFiles.add("someOtherDozerBeanMappings.xml");
                 DozerBeanMapper mapper = new DozerBeanMapper();
                 mapper.setMappingFiles(myMappingFiles);
                 String p="com.ihx.util.Fileobject";
                 String p1="com.ihx.model.Test";
                 mapper.map(p, p1, "a");
1

There are 1 answers

3
M21B8 On
List myMappingFiles = new ArrayList();
myMappingFiles.add("dozerMapping.xml");
// myMappingFiles.add("someOtherDozerBeanMappings.xml");
DozerBeanMapper mapper = new DozerBeanMapper();
mapper.setMappingFiles(myMappingFiles);
com.ihx.util.Fileobject p= new Fileobject();
p.setNameId("testNameId");
com.ihx.model.Test p1 = new com.ihx.model.Test();
mapper.map(p, p1, "a");
String mappedNameId = p1.getNameId();
// This mappedNameId should now be the testNameId we set earlier. 

p and p1 need to be the actual class objects to transform, with the data in. p1 then gets the data mapped into it from p.