use of krati.io.SerializationException in project camel by apache.
the class KratiDefaultSerializer method deserialize.
/**
* Deserialize an object from its raw bytes generated by {{@link #serialize(Object)}.
*
* @param binary - the raw bytes from which an object is constructed.
* @return an object constructed from the raw bytes.
* @throws SerializationException if the object cannot be constructed from the raw bytes.
*/
@SuppressWarnings("unchecked")
public T deserialize(byte[] binary) throws SerializationException {
T result = null;
ObjectInputStream ois = null;
if (binary == null) {
return null;
}
// TODO: should use Camel's ClassResolver for classloading
ByteArrayInputStream bais = new ByteArrayInputStream(binary);
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
try {
ois = new ObjectInputStream(bais) {
@Override
public Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
try {
return classLoader.loadClass(desc.getName());
} catch (Exception e) {
}
return super.resolveClass(desc);
}
};
result = (T) ois.readObject();
} catch (IOException e) {
LOG.warn("Error while deserializing object. Null will be used.", e);
} catch (ClassNotFoundException e) {
LOG.warn("Could not find class while deserializing object. Null will be used.", e);
} finally {
IOHelper.close(ois, bais);
}
return result;
}
Aggregations