Java tutorial
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; public class Main { public static byte[] objectToByte(Object obj) throws IOException { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ObjectOutputStream os = new ObjectOutputStream(outputStream); os.writeObject(obj); return outputStream.toByteArray(); } }