Here you can find the source of serialize(T object)
public static <T extends Serializable> byte[] serialize(T object)
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { public static <T extends Serializable> byte[] serialize(T object) { if (null == object) return null; ObjectOutputStream oos = null; ByteArrayOutputStream baos = null; byte[] bytes = null; try {/*from w w w . java 2 s. c o m*/ baos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(baos); oos.writeObject(object); bytes = baos.toByteArray(); } catch (Exception e) { throw new RuntimeException("Serialize Object Filed:" + e.getMessage()); } return bytes; } }