Here you can find the source of serializeToString(Object object)
public static String serializeToString(Object object) throws IOException
//package com.java2s; /* (c) 2014 LinkedIn Corp. All rights reserved. * /*from ww w . jav a 2s.c o m*/ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use * this file except in compliance with the License. You may obtain a copy of the * License at http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. */ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import javax.xml.bind.DatatypeConverter; public class Main { public static String serializeToString(Object object) throws IOException { byte[] bytes = serializeToBytes(object); return DatatypeConverter.printBase64Binary(bytes); } public static byte[] serializeToBytes(Object object) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos); oos.writeObject(object); oos.close(); return bos.toByteArray(); } }