Here you can find the source of serialize(T t)
@SuppressWarnings("unchecked") public static <T extends Serializable> T serialize(T t)
//package com.java2s; //License from project: Apache License import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; public class Main { @SuppressWarnings("unchecked") public static <T extends Serializable> T serialize(T t) { try {// w w w. ja v a 2s. c o m ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(t); oos.close(); final byte[] ba = baos.toByteArray(); baos.close(); ByteArrayInputStream bais = new ByteArrayInputStream(ba); ObjectInputStream ois = new ObjectInputStream(bais); Object returnValue = ois.readObject(); ois.close(); return (T) returnValue; } catch (IOException e) { throw new RuntimeException(e); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } }