java - how to map different Field names from one Array inside one object to a List which is inside another Object -


this helper class.

customer.java

package com;  public class customer {     public string customername;     public string customeradd;     public customer() {         // todo auto-generated constructor stub     }     public string getcustomername() {         return customername;     }     public string getcustomeradd() {         return customeradd;     }     public void setcustomername(string customername) {         this.customername = customername;     }     public void setcustomeradd(string customeradd) {         this.customeradd = customeradd;     }  } 

this helper class

customerdest.java

package com;  public class customerdest {     public string customername;     public string getcustomername() {         return customername;     }     public string getcustomeraddr() {         return customeraddr;     }     public void setcustomername(string customername) {         customername = customername;     }     public void setcustomeraddr(string customeraddr) {         this.customeraddr = customeraddr;     }     public string customeraddr;     public customerdest() {         // todo auto-generated constructor stub     }  } 

this destination class reying set values , can main method class

desticlass .java

package com;  import java.util.list;  public class desticlass {     public list<customerdest> custlist;     public desticlass() {         // todo auto-generated constructor stub     }     public list<customerdest> getcustlist() {         return custlist;     }      public void setcustlist(list<customerdest> custlist) {         this.custlist = custlist;     }  } 

this source class trying set values.

sourceclass.java

package com;  public class sourceclass {     public customer[] cust;     public sourceclass() {         // todo auto-generated constructor stub     }      public customer[] getcust() {         return cust;     }      public void setcust(customer[] cust) {         this.cust = cust;     }  } 

this dozer mapping file.

dozer-bean-mappings.xml

<?xml version="1.0" encoding="utf-8"?> <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">  <configuration> <stop-on-errors>true</stop-on-errors> <date-format>mm/dd/yyyy hh:mm</date-format> <wildcard>true</wildcard> </configuration> <mapping map-id="a">         <class-a>com.sourceclass</class-a>         <class-b>com.desticlass</class-b>         <field>         <a>cust</a>         <b>custlist</b>         <a-hint>com.customer</a-hint>          <b-hint>com.customerdest</b-hint>          </field>       </mapping>     </mappings> 

this main method class, here have written codes dozer mapping..

mainmethodclass.java

package com;  import java.util.list; import java.util.arrays;  import org.dozer.dozerbeanmapper;  public class mainmethodclass {      public static void main(string[] args) {         string file = "dozer-bean-mappings.xml";         customer cus=new customer();         cus.setcustomeradd("sagar");         cus.setcustomeradd("mas");         sourceclass sc=new sourceclass();         customer cusarr[]=new customer[10];         cusarr[0]=cus;         sc.setcust(cusarr);         desticlass dc=new desticlass();         dozerbeanmapper mapper = new dozerbeanmapper(arrays.aslist(new string[]{file}));         mapper.map(sc, dc, "a");         list lista=(list) dc.getcustlist();     }  } 

i trying map array , list inside 2 pojos using dozer, please suggest me.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -