Java Utililty Methods Object Serialize and Deserialize

List of utility methods to do Object Serialize and Deserialize

Description

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

Method

Objectdeserialise(byte[] bytes)
deserialise
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bais);
Object object = ois.readObject();
ois.close();
return object;
SerializabledeserialiseFromByteArray(byte b[])
You better have a good reason for using this.
return ((Serializable) (new ObjectInputStream(new ByteArrayInputStream(b))).readObject());
TdeserializaObjeto(byte[] bytes, Class tipo)
Deseriza un array de bytes en un objeto java del tipo indicado.
if (bytes == null) {
    return null;
ByteArrayInputStream byteIn = new ByteArrayInputStream(bytes);
ObjectInputStream in = new ObjectInputStream(byteIn);
@SuppressWarnings("unchecked")
T obj = (T) in.readObject();
in.close();
...
Tdeserialize(final String serializable, final Class valueType)
deserialize
try (final ObjectInputStream in = new ObjectInputStream(
        new ByteArrayInputStream((byte[]) Base64.getDecoder().decode(serializable)))) {
    return valueType.cast(in.readObject());
Objectdeserialize(String name)
deserialize
try {
    FileInputStream fileIn = new FileInputStream(name);
    ObjectInputStream in = new ObjectInputStream(fileIn);
    Object object = in.readObject();
    in.close();
    fileIn.close();
    return object;
} catch (Exception i) {
...
Propertiesdeserialize(String serialized)
deserialize
StringReader reader = new StringReader(serialized);
Properties properties = new Properties();
properties.load(reader);
reader.close();
return properties;
Objectdeserialize(String serializedObject)
deserialize
try {
    byte b[] = Base64.getDecoder().decode(serializedObject);
    ByteArrayInputStream bi = new ByteArrayInputStream(b);
    ObjectInputStream si = new ObjectInputStream(bi);
    return si.readObject();
} catch (Exception e) {
    System.out.println(e);
    return null;
...
Objectdeserialize(String str)
deserialize
if (str == null || str.length() == 0) {
    return null;
try {
    ByteArrayInputStream serialObj = new ByteArrayInputStream(decodeBytes(str));
    ObjectInputStream objStream = new ObjectInputStream(serialObj);
    return objStream.readObject();
} catch (Exception e) {
...
ObjectdeSerialize(String str)
de Serialize
byte[] byteFromStr = str.getBytes("ISO-8859-1");
return deSerialize(byteFromStr);
TdeserializeAndCheckObject(final byte[] object, final Class type)
Decode and serialize object.
final Object result = deserialize(object);
if (!type.isAssignableFrom(result.getClass())) {
    throw new ClassCastException(
            "Decoded object is of type " + result.getClass() + " when we were expecting " + type);
return (T) result;