Here you can find the source of getBytesFromObject(Serializable obj)
public static byte[] getBytesFromObject(Serializable obj) throws Exception
//package com.java2s; //License from project: Apache License import java.io.ByteArrayOutputStream; import java.io.ObjectOutputStream; import java.io.Serializable; public class Main { public static byte[] getBytesFromObject(Serializable obj) throws Exception { if (obj == null) { return null; }/*from ww w . j a v a 2 s.c o m*/ ByteArrayOutputStream bo = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bo); oos.writeObject(obj); return bo.toByteArray(); } }