Java tutorial
//package com.java2s; import java.io.*; public class Main { static public byte[] getObjectBytes(Object o) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(o); oos.close(); return baos.toByteArray(); } }