Here you can find the source of serializeObject(final Object object)
public static byte[] serializeObject(final Object object)
//package com.java2s; /*/*from w ww.ja v a 2 s. c om*/ * SwingTech Software - http://cooksarm.sourceforge.net/ * * Copyright (C) 2011 Joe Rice All rights reserved. * * SwingTech Cooks Arm is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 3 of the License, or (at your option) any * later version. * * SwingTech Cooks Arm is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * SwingTech Cooks Arm; If not, see <http://www.gnu.org/licenses/>. */ import java.io.ByteArrayOutputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; public class Main { public static byte[] serializeObject(final Object object) { ObjectOutput out = null; byte[] buf = null; if (object == null) { return null; } try { // Serialize to a byte array final ByteArrayOutputStream bos = new ByteArrayOutputStream(); out = new ObjectOutputStream(bos); out.writeObject(object); out.close(); // Get the bytes of the serialized object buf = bos.toByteArray(); } catch (final Exception e) { throw new RuntimeException("Error trying to serializeObject the following object: " + object, e); } return buf; } }