September 05, 2017

How to copy one object from another in Java

Converting one object into another in java


Main class


import org.dozer.DozerBeanMapper; /** * @author belazy * */ public class MainClass { public static void main(String[] args) { DozerBeanMapper mapper = new DozerBeanMapper(); mapper.setMappingFiles(Arrays.asList("dozer_mapping.xml")); Employee employee = new Employee("Sachin", "tendulkar", 45); EmployeeNew employeeNew = mapper.map(employee, EmployeeNew.class); System.out.println(employeeNew.getEmployeeFirstName()); } }

EmployeeTest


/** * */ package com.belazy.dozer; /** * @author belazy * */ public class EmployeeTest { private String firstName; private String lastName; private int age; public EmployeeTest(String firstName, String lastName, int age) { // TODO Auto-generated constructor stub this.firstName = firstName; this.lastName = lastName; this.age = age; } /** * @return the firstName */ public String getFirstName() { return firstName; } /** * @param firstName the firstName to set */ public void setFirstName(String firstName) { this.firstName = firstName; } /** * @return the lastName */ public String getLastName() { return lastName; } /** * @param lastName the lastName to set */ public void setLastName(String lastName) { this.lastName = lastName; } /** * @return the age */ public int getAge() { return age; } /** * @param age the age to set */ public void setAge(int age) { this.age = age; } }

EmployeeNew class

/** * */ package com.belazy.dozer; /** * @author belazy * */ public class EmployeeNew { private String employeeFirstName; private String employeeLastName; private int employeeAge; public EmployeeNew() { // TODO Auto-generated constructor stub } public EmployeeNew(String employeeFirstName,String employeeLastName, int employeeAge ) { // TODO Auto-generated constructor stub this.employeeAge = employeeAge; this.employeeLastName = employeeLastName; this.employeeFirstName = employeeFirstName; } /** * @return the employeeFirstName */ public String getEmployeeFirstName() { return employeeFirstName; } /** * @param employeeFirstName the employeeFirstName to set */ public void setEmployeeFirstName(String employeeFirstName) { this.employeeFirstName = employeeFirstName; } /** * @return the employeeLastName */ public String getEmployeeLastName() { return employeeLastName; } /** * @param employeeLastName the employeeLastName to set */ public void setEmployeeLastName(String employeeLastName) { this.employeeLastName = employeeLastName; } /** * @return the employeeAge */ public int getEmployeeAge() { return employeeAge; } /** * @param employeeAge the employeeAge to set */ public void setEmployeeAge(int employeeAge) { this.employeeAge = employeeAge; } }

Dozer mapping. xml

<mappings xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://dozer.sourceforge.net" xsi:schemalocation="http://dozer.sourceforge.net
      http://dozer.sourceforge.net/schema/beanmapping.xsd">
    <mapping>
        <class-a>com.belazy.dozer.EmployeeTest</class-a>
        <class-b>com.belazy.dozer.EmployeeNew</class-b>
        <field>
            <a href="https://www.blogger.com/null">firstName</a>
            <b>employeeFirstName</b>
        </field>
        <field>
            <a href="https://www.blogger.com/null">lastName</a>
            <b>employeeLastName</b>
        </field>
        <field>
            <a href="https://www.blogger.com/null">age</a>
            <b>employeeAge</b>
        </field>
    </mapping>
</mappings>




http://www.java2s.com/Open-Source/Java_Free_Code/Tutorial/Download_travelport_uapi_tutorial_Free_Java_Code.htm

htm
http://testws.galileo.com/GWSSample/Help/GWSHelp/java_sample_step_2__booking_an_air_reservation.htm

https://support.travelport.com/webhelp/GWS/Content/Overview/Getting_Started/Sample_Web_Service_Calls/Java_Sample_Step_1__Air_Availability_Request.htm


http://www.galileo.co.kr/document/Galileo%20Web%20Services%20Product%20Overview.pdf

No comments:

Post a Comment

Your feedback may help others !!!

Facebook comments