Here you can find the source of serializeAndDeserialize(Object o)
public static Object serializeAndDeserialize(Object o) throws IOException, ClassNotFoundException
//package com.java2s; /*/*from ww w. j a v a 2 s. c o m*/ * The Spring Framework is published under the terms * of the Apache Software License. */ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; public class Main { public static Object serializeAndDeserialize(Object o) throws IOException, ClassNotFoundException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(o); oos.flush(); baos.flush(); byte[] bytes = baos.toByteArray(); ByteArrayInputStream is = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(is); Object o2 = ois.readObject(); return o2; } }