Java Utililty Methods Object Deserialize

List of utility methods to do Object Deserialize

Description

The list of methods to do Object Deserialize are organized into topic(s).

Method

TdeserializeObject(byte[] data, Class clazz)
deserialize Object
return deserializeObject(new ByteArrayInputStream(data), clazz);
TdeserializeObject(byte[] obj)
Deserializes an object from its byte format.
try (ByteArrayInputStream in = new ByteArrayInputStream(obj)) {
    try (ObjectInputStream r = new ObjectInputStream(in)) {
        return (T) r.readObject();
ObjectdeserializeObject(byte[] serializedObj)
Deserializes Object from byte array.
InputStream is = new ByteArrayInputStream(serializedObj);
ObjectInput oi;
oi = new ObjectInputStream(is);
return oi.readObject();
ObjectdeserializeObject(File file)
This method deserializes an object from an input stream.
FileInputStream fis = new FileInputStream(file);
Object object = null;
try {
    ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(fis));
    object = ois.readObject();
} finally {
    fis.close();
return object;
TdeserializeObject(File inFile)
deserialize Object
return deserializeObject(new FileInputStream(inFile), true);
TdeserializeObject(final byte[] b)
Serializes an object in memory.
try {
    final ByteArrayInputStream bin = new ByteArrayInputStream(b);
    final ObjectInputStream cin = new ObjectInputStream(bin);
    return (T) cin.readObject();
} catch (ClassNotFoundException | IOException e) {
    e.printStackTrace(); 
return null;
...
ObjectdeserializeObject(final byte[] bytes)
deserialize Object
ObjectInputStream in = null;
Object obj = null;
if (bytes == null) {
    return null;
try {
    in = new ObjectInputStream(new ByteArrayInputStream(bytes));
    obj = in.readObject();
...
ObjectdeserializeToObject(byte[] bytes)
deserialize To Object
try {
    ByteArrayInputStream bos = new ByteArrayInputStream(bytes);
    ObjectInputStream objectInputStream = new ObjectInputStream(bos);
    Object readObject = objectInputStream.readObject();
    objectInputStream.close();
    return readObject;
} catch (Exception e) {
    throw new RuntimeException("Exception trying to deserialize bytes to obj, bytes=" + new String(bytes),
...