protected function unserializeType($value, $type)
    {
        if ($type === self::TYPE_JSON) {
            // overwrite the doctrine json type since it uses the assoc
            // parameter. This is a problem for empty objects since we cant
            // distinguish between an empty array or object
            if ($value === null) {
                return null;
            } elseif ($value === '') {
                return new \stdClass();
            } elseif (is_resource($value)) {
                $value = stream_get_contents($value);
            }

            return json_decode($value);
        } else {
            return $this->connection->convertToPHPValue(
                $value,
                TypeMapper::getDoctrineTypeByType($type)
            );
        }
    }