Here you can find the source of serialize(Serializable object)
public static byte[] serialize(Serializable object) throws IOException
//package com.java2s; //License from project: Apache License import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.io.Serializable; public class Main { public static byte[] serialize(Serializable object) throws IOException { return serialize(object, Thread.currentThread().getContextClassLoader()); }// w ww . java2 s .c o m public static byte[] serialize(Serializable object, ClassLoader classLoader) throws IOException { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ObjectOutput out = null; byte[] result; try { out = new ObjectOutputStream(outputStream); out.writeObject(object); result = outputStream.toByteArray(); } finally { try { if (out != null) { out.close(); } } catch (IOException ex) { // ignore close exception } try { outputStream.close(); } catch (IOException ex) { // ignore close exception } } return result; } }