Here you can find the source of serialize(Object obj)
public static byte[] serialize(Object obj) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; public class Main { public static byte[] serialize(Object obj) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (ObjectOutputStream out = new ObjectOutputStream(baos)) { out.writeObject(obj);/*from www . ja v a2 s .c o m*/ return baos.toByteArray(); } finally { baos.close(); } } }