Here you can find the source of deserialize(byte[] bytes, Class
Parameter | Description |
---|---|
bytes | Byte array to be deserialized. |
clazz | Class type the object should be deserialized into. |
public static <T extends Serializable> T deserialize(byte[] bytes, Class<T> clazz) throws IOException, ClassNotFoundException
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.Serializable; public class Main { /**//from w w w. j ava 2 s. c o m * Deserialize a byte array into an object. The object has to implement {@link Serializable} interface. * * @param bytes Byte array to be deserialized. * @param clazz Class type the object should be deserialized into. * @return Object deserialized from the byte array. */ public static <T extends Serializable> T deserialize(byte[] bytes, Class<T> clazz) throws IOException, ClassNotFoundException { ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes); ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream); Object object = objectInputStream.readObject(); return clazz.cast(object); } }