Here you can find the source of getBytes(final Serializable obj)
public static byte[] getBytes(final Serializable obj) throws Exception
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayOutputStream; import java.io.ObjectOutputStream; import java.io.Serializable; public class Main { public static byte[] getBytes(final Serializable obj) throws Exception { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try {/* www .j ava2s.c o m*/ ObjectOutputStream oos = new ObjectOutputStream(bos); try { oos.writeObject(obj); } finally { oos.close(); } } finally { bos.close(); } return bos.toByteArray(); } }