Here you can find the source of serialize(@Nullable Object value)
@Nullable public static byte[] serialize(@Nullable Object value)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import javax.annotation.Nullable; public class Main { /**//w ww .j ava 2 s . c om * Turns an object into a byte array. * * @return serialized object or {@code null} if {@code value} is {@code null} */ @Nullable public static byte[] serialize(@Nullable Object value) { if (value == null) { return null; } ByteArrayOutputStream objectBytes = new ByteArrayOutputStream(); try (ObjectOutputStream oos = new ObjectOutputStream(objectBytes)) { oos.writeObject(value); } catch (IOException e) { throw new IllegalArgumentException("Unable to serialize: " + value, e); } return objectBytes.toByteArray(); } }