Here you can find the source of deserialize(final String serializable, final Class
Parameter | Description |
---|---|
serializable | the String representation of the Serializable object |
valueType | the type of value to deserialize |
Parameter | Description |
---|---|
IOException | an exception |
ClassNotFoundException | an exception |
public static <T extends Serializable> T deserialize(final String serializable, final Class<T> valueType) throws IOException, ClassNotFoundException
//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()); } } }