'Smart cloning' using JBoss serialization

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/

0 comments:

Newer Post Older Post Home

Blogger Template by Blogcrowds