Here you can find the source of serialize(Object object)
public static String serialize(Object object) throws IOException
//package com.java2s; /*//w ww.java 2 s.c o m * Hibernate Search, full-text search for your domain model * * License: GNU Lesser General Public License (LGPL), version 2.1 or later * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. */ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import java.util.Base64; public class Main { public static String serialize(Object object) throws IOException { try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos)) { oos.writeObject(object); oos.flush(); byte bytes[] = baos.toByteArray(); return Base64.getEncoder().encodeToString(bytes); } } }