Here you can find the source of serialize(Object value)
public static byte[] serialize(Object value)
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { public static byte[] serialize(Object value) { if (value == null) { throw new NullPointerException("Can't serialize null"); }//from ww w . ja v a2s . c o m byte[] rv = null; ByteArrayOutputStream bos = null; ObjectOutputStream os = null; try { bos = new ByteArrayOutputStream(); os = new ObjectOutputStream(bos); os.writeObject(value); os.close(); bos.close(); rv = bos.toByteArray(); } catch (Exception e) { e.printStackTrace(); System.out.println("serialize error"); } finally { close(os); close(bos); } return rv; } private static void close(Closeable closeable) { if (closeable != null) try { closeable.close(); } catch (IOException e) { e.printStackTrace(); System.out.println("close stream error"); } } }