Java tutorial
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.ObjectOutputStream; public class Main { public static byte[] serialize(Object obj) { ByteArrayOutputStream out = new ByteArrayOutputStream(); ObjectOutputStream os; try { os = new ObjectOutputStream(out); os.writeObject(obj); return out.toByteArray(); } catch (Exception e) { e.printStackTrace(); } return null; } }