Java tutorial
//package com.java2s; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; import java.nio.ByteBuffer; public class Main { public static Object getObject(byte[] bytes) throws IOException, ClassNotFoundException { ByteArrayInputStream bi = new ByteArrayInputStream(bytes); ObjectInputStream oi = new ObjectInputStream(bi); Object obj = oi.readObject(); bi.close(); oi.close(); return obj; } public static Object getObject(ByteBuffer byteBuffer) throws ClassNotFoundException, IOException { InputStream input = new ByteArrayInputStream(byteBuffer.array()); ObjectInputStream oi = new ObjectInputStream(input); Object obj = oi.readObject(); input.close(); oi.close(); byteBuffer.clear(); return obj; } }