Here you can find the source of obj2Bytes(Object obj)
public static byte[] obj2Bytes(Object obj)
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.ObjectOutputStream; public class Main { public static byte[] obj2Bytes(Object obj) { byte[] result = null; try {// w w w . j a v a2 s .c o m ByteArrayOutputStream bo = new ByteArrayOutputStream(); ObjectOutputStream oo = new ObjectOutputStream(bo); oo.writeObject(obj); result = bo.toByteArray(); bo.close(); oo.close(); } catch (Exception e) { e.printStackTrace(); } return result; } }