Here you can find the source of serialize(Object object)
public static byte[] serialize(Object object) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2014 EURA NOVA.// ww w .j a va2 s . co m * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v2.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html * * Contributors: * Aldemar Reynaga - initial API and implementation * Salim Jouili - initial API and implementation ******************************************************************************/ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutput; import java.io.ObjectOutputStream; public class Main { public static byte[] serialize(Object object) throws IOException { return convertObjectToBytes(object); } public static byte[] convertObjectToBytes(Object object) throws IOException { byte[] msg = null; ByteArrayOutputStream bos; ObjectOutput out = null; bos = new ByteArrayOutputStream(); out = new ObjectOutputStream(bos); out.writeObject(object); out.flush(); bos.flush(); msg = bos.toByteArray(); out.close(); bos.close(); return msg; } }