Java Object Serialize and Deserialize deserialize(final String serializable, final Class valueType)

Here you can find the source of deserialize(final String serializable, final Class valueType)

Description

deserialize

License

Apache License

Parameter

Parameter Description
serializable the String representation of the Serializable object
valueType the type of value to deserialize

Exception

Parameter Description
IOException an exception
ClassNotFoundException an exception

Return

the deserialized

Declaration

public static <T extends Serializable> T deserialize(final String serializable, final Class<T> valueType)
        throws IOException, ClassNotFoundException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.ByteArrayInputStream;

import java.io.IOException;
import java.io.ObjectInputStream;

import java.io.Serializable;
import java.util.Base64;

public class Main {
    /**//from  w  w  w.  j av a 2  s. c om
     * @param serializable the {@link String} representation of the
     *            {@link Serializable} object
     * @param valueType the type of value to deserialize
     * @return the deserialized {@link Object}
     * @throws IOException
     * @throws ClassNotFoundException
     */
    public static <T extends Serializable> T deserialize(final String serializable, final Class<T> valueType)
            throws IOException, ClassNotFoundException {
        try (final ObjectInputStream in = new ObjectInputStream(
                new ByteArrayInputStream((byte[]) Base64.getDecoder().decode(serializable)))) {
            return valueType.cast(in.readObject());
        }
    }
}

Related

  1. deserialise(byte[] bytes)
  2. deserialiseFromByteArray(byte b[])
  3. deserializaObjeto(byte[] bytes, Class tipo)
  4. deserialize(String name)
  5. deserialize(String serialized)
  6. deserialize(String serializedObject)
  7. deserialize(String str)