Here you can find the source of serialize(Object msg)
public static ByteBuffer serialize(Object msg)
//package com.java2s; //License from project: Open Source License import java.nio.*; import java.io.*; public class Main { public static ByteBuffer serialize(Object msg) { try {/*w w w .j a va2 s .co m*/ try (ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(bos)) { oos.writeObject(msg); oos.close(); return ByteBuffer.wrap(bos.toByteArray()); } } catch (IOException e) { } return null; } }