I was trying to look for an easier way to clone objects (easier than using java.lang.Cloneable class) and I found out that using the jboss serialization library is easier and faster. The following code shows how to clone an object:
try {
JBossObjectOutputStream jbossSerializer = new JBossObjectOutputStream(null);
User newUser = (User) jbossSerializer.smartClone(user);
System.out.println(newUser);
}
catch(Exception e) {
System.out.println("EXCEPTION CAUGHT: " + e.getMessage());
}
using jboss serialization, you can also clone "Non serializable" objects.
you will need jboss-serialization.jar
Reference:
http://blogs.jboss.com/blog/clebert/
Labels: cloning, jboss, serialization
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment