Here you can find the source of serialize(@Nullable final Object obj)
@Nullable public static byte[] serialize(@Nullable final Object obj)
//package com.java2s; //License from project: Apache License import javax.annotation.Nullable; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; public class Main { @Nullable public static byte[] serialize(@Nullable final Object obj) { if (obj == null) { return null; }//from ww w .ja va 2 s . c o m final ByteArrayOutputStream os = new ByteArrayOutputStream(1024); try { final ObjectOutputStream out = new ObjectOutputStream(os); try { out.writeObject(obj); } finally { out.close(); } return os.toByteArray(); } catch (IOException ioe) { throw new IllegalArgumentException("Trying to persist an object that can't be serialized", ioe); } } }