Here you can find the source of serializeAndDeserialize(T obj)
@SuppressWarnings("unchecked") public static <T> T serializeAndDeserialize(T obj) throws IOException, ClassNotFoundException
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; public class Main { @SuppressWarnings("unchecked") public static <T> T serializeAndDeserialize(T obj) throws IOException, ClassNotFoundException { ByteArrayOutputStream buf = new ByteArrayOutputStream(); try (ObjectOutputStream out = new ObjectOutputStream(buf)) { out.writeObject(obj);//from w w w . j a v a2s. c om } try (ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(buf.toByteArray()))) { return (T) in.readObject(); } } }