August 24, 2017

Copying one POJO object to another without clone

/**
 * MainClass
 */
package com.belazy.dozer;

import org.dozer.DozerBeanMapper;

/**
 * @author nijesh
 *
 */
public class MainClass {

public static void main(String[] args) {
DozerBeanMapper mapper = new DozerBeanMapper();
Employee employee = new Employee("Sachin", "tendulkar", 45);
EmployeeNew employeeNew = mapper.map(employee, EmployeeNew.class);
System.out.println(employeeNew.getEmployeeFirstName());
}

}

/**
 *
 */
package com.belazy.dozer;

/**
 * @author nijesh
 *
 */
public class Employee {

private String employeeFirstName;
private String employeeLastName;
private int employeeAge;

public Employee(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;
}



}




/**
 *
 */
package com.belazy.dozer;

/**
 * @author nijesh
 *
 */
public class EmployeeNew {
private String employeeFirstName;
private String employeeLastName;
private int employeeAge;

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;
}





}

Jar files needed

dozer-5.4.0.jar
logback-classic-0.9.jar
logback-core-0.9.6.jar
slf4j.jar
slf4j-log4j13-1.0.1.jar


errors
Failed to instantiate [ch.qos.logback.classic.LoggerContext]
Reported exception:
java.lang.NoSuchMethodError: ch.qos.logback.classic.util.ContextInitializer.<init>(Lch/qos/logback/classic/LoggerContext;)V
at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:85)
at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:56)
at org.slf4j.LoggerFactory.getSingleton(LoggerFactory.java:189)
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:112)
at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:105)
at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:235)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:208)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:221)
at org.dozer.DozerBeanMapper.<clinit>(DozerBeanMapper.java:67)
at com.belazy.dozer.MainClass.main(MainClass.java:15)
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.dozer.stats.StatisticsManagerImpl.<init>(StatisticsManagerImpl.java:39)
at org.dozer.stats.GlobalStatistics.<init>(GlobalStatistics.java:29)
at org.dozer.stats.GlobalStatistics.<clinit>(GlobalStatistics.java:24)
at org.dozer.DozerBeanMapper.<clinit>(DozerBeanMapper.java:68)
at com.belazy.dozer.MainClass.main(MainClass.java:15)
Caused by: java.lang.SecurityException: class "org.slf4j.impl.MessageFormatter"'s signer information does not match signer information of other classes in the same package
at java.lang.ClassLoader.checkCerts(Unknown Source)
at java.lang.ClassLoader.preDefineClass(Unknown Source)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at ch.qos.logback.classic.spi.LoggingEvent.<init>(LoggingEvent.java:114)
at ch.qos.logback.classic.Logger.filterAndLog(Logger.java:421)
at ch.qos.logback.classic.Logger.filterAndLog(Logger.java:430)
at ch.qos.logback.classic.Logger.info(Logger.java:494)
at org.dozer.config.GlobalSettings.loadGlobalSettings(GlobalSettings.java:113)
at org.dozer.config.GlobalSettings.<init>(GlobalSettings.java:67)
at org.dozer.config.GlobalSettings.<clinit>(GlobalSettings.java:46)
... 5 more


http://javabelazy.blogspot.in/

Facebook comments