Here you can find the source of serialize(T obj)
public static <T> byte[] serialize(T obj)
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; public class Main { public static <T> byte[] serialize(T obj) { ObjectOutputStream oos = null; ByteArrayOutputStream os = null; try {//from w w w . j a va2s . c om os = new ByteArrayOutputStream(); oos = new ObjectOutputStream(os); oos.writeObject(obj); return os.toByteArray(); } catch (IOException e) { e.printStackTrace(); } finally { if (oos != null) { try { os.close(); oos.close(); } catch (IOException e) { e.printStackTrace(); } } } return null; } }