Here you can find the source of serialize(T object)
Parameter | Description |
---|---|
object | Object to be serialized. |
public static <T extends Serializable> byte[] serialize(T object) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import java.io.Serializable; public class Main { /**/*from w ww . j av a 2 s . com*/ * Serialize an object into a byte array. The object has to implement {@link Serializable} interface. * * @param object Object to be serialized. * @return Byte array serialized from the object. */ public static <T extends Serializable> byte[] serialize(T object) throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); objectOutputStream.writeObject(object); objectOutputStream.close(); return byteArrayOutputStream.toByteArray(); } }