Here you can find the source of serialize(Object obj)
public static byte[] serialize(Object obj)
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; public class Main { public static byte[] serialize(Object obj) { try {/* www.ja v a 2s . c om*/ ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(obj); oos.close(); return baos.toByteArray(); } catch (IOException e) { throw new RuntimeException("error serializing " + obj, e); } } }