Here you can find the source of serializeAndGetObject(Object obj)
public static Object serializeAndGetObject(Object obj) throws ClassNotFoundException, IOException
//package com.java2s; //License from project: Apache 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 serializeAndGetObject(Object obj) throws ClassNotFoundException, IOException { return getObjectFromByteArray(getByteObject(obj)); }// ww w .j a v a 2 s .c o m private static Object getObjectFromByteArray(byte[] byteArray) throws IOException, ClassNotFoundException { ByteArrayInputStream bs = new ByteArrayInputStream(byteArray); ObjectInputStream is = new ObjectInputStream(bs); Object serializableObject = is.readObject(); is.close(); return serializableObject; } private static byte[] getByteObject(Object obj) throws IOException { ByteArrayOutputStream bs = new ByteArrayOutputStream(); ObjectOutputStream os = new ObjectOutputStream(bs); os.writeObject(obj); os.close(); return bs.toByteArray(); } }