Here you can find the source of serializeToString(Object o)
public static String serializeToString(Object o) throws Exception
//package com.java2s; /*/*from w w w . j ava 2s .c o m*/ * Copyright 2001-2008 Aqris Software AS. All rights reserved. * * This program is dual-licensed under both the Common Development * and Distribution License ("CDDL") and the GNU General Public * License ("GPL"). You may elect to use one or the other of these * licenses. */ import java.io.ByteArrayOutputStream; import java.io.ObjectOutputStream; public class Main { public static String serializeToString(Object o) throws Exception { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); ObjectOutputStream stream = new ObjectOutputStream(bytes); stream.writeObject(o); stream.flush(); return bytesToString(bytes.toByteArray()); } private static String bytesToString(byte[] bytes) { StringBuffer result = new StringBuffer(); for (int i = 0; i < bytes.length; i++) { result.append(bytes[i]); result.append(" "); } return result.toString(); } }