Here you can find the source of serialize(Object object)
public static byte[] serialize(Object object)
//package com.java2s; //License from project: Open Source License import java.io.*; public class Main { public static byte[] serialize(Object object) { if (object == null) { return null; }//from w w w.j a va 2 s . co m ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); try { ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(object); oos.flush(); } catch (IOException ex) { throw new IllegalArgumentException("Failed to serialize object of type: " + object.getClass(), ex); } return baos.toByteArray(); } }