class JdkSerializerDeserializer implements SerializerDeserializer {

  @Override
  public Object deserialize(byte[] data) {
    if (data == null) {
      return null;
    }
    // For deserializing objects we use specific class loader of
    // the session manager to insure it was the same one used
    // when creating serialized objects.
    ClassLoader classLoader = sessionManager.getSessionClassLoader();
    if (classLoader == null) {
      classLoader = Thread.currentThread().getContextClassLoader();
    }
    try (ByteArrayInputStream in = new ByteArrayInputStream(data);
        ObjectInputStream is = new ClassLoaderObjectInputStream(classLoader, in)) {
      Object obj = is.readObject();
      // Incrementing metrics
      deserializedData.inc(data.length);
      deserializedHistogram.update(data.length);
      return obj;
    } catch (IOException | ClassNotFoundException e) {
      throw new IllegalStateException("Unable to deserialize object. See stacktrace for more information.", e);
    }
  }

}