Here you can find the source of serialize(Object object)
public static byte[] serialize(Object object)
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { public static byte[] serialize(Object object) { ObjectOutputStream oos = null; ByteArrayOutputStream baos = null; if (null == object) return null; try {//from w w w. jav a 2 s. c o m baos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(baos); oos.writeObject(object); byte[] bytes = baos.toByteArray(); return bytes; } catch (Exception e) { e.printStackTrace(); return null; } finally { try { oos.close(); baos.close(); } catch (IOException e) { e.printStackTrace(); } } } }