Here you can find the source of serialize(Object obj)
public static byte[] serialize(Object obj)
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { public static byte[] serialize(Object obj) { ByteArrayOutputStream b = new ByteArrayOutputStream(); ObjectOutputStream o;/*from ww w. j a v a 2 s . com*/ try { o = new ObjectOutputStream(b); o.writeObject(obj); } catch (IOException e) { e.printStackTrace(); } return b.toByteArray(); } }