Converts some input to a serialized string

@param mixed $data Input as an array, String, Object, and so on
@return null|string null at fault, string on success
355389
public function convert($data)
    {
        if (empty($data) || ($out = @serialize($data)) === false)
            return null;

        return $out;
    }
874694
private function deserializeData($data)
    {
        $result = $this->get('jms_serializer')->deserialize(
            $data,
            $this->getTargetGroupRepository()->getClassName(),
            'json',
            DeserializationContext::create()
                ->setSerializeNull(true)
        );

        return $result;
    }
445298
public static String serialize(Object data) {
        String ret=null;

        if (data != null) {
            if (data.getClass() == String.class) {
                ret = (String)data;
            } else if (data instanceof byte[]) {
                ret = new String((byte[])data);
            } else {
                try {
                    ret = mapper.writeValueAsString(data);
                } catch (JsonProcessingException e) {
                    if (log.isLoggable(Level.FINEST)) {
                        log.log(Level.FINEST, "Failed to serialize object into json", e);
                    }
                }
            }
        }
768184
protected static function dataToString($data)
    {
        if (!is_string($data))
        {
            try
            {
                $data = \GuzzleHttp\json_encode($data);
            }
            catch (\InvalidArgumentException $e)
            {

            }
        }

        return $data;
    }
1181187
public function decode($data)
    {
        $data = (string) $data;
        // skip empty strings (that cause "Syntax error"?)
        if ($data === '') {
            return null;
        }

        $data = json_decode($data, $this->options['assoc'], $this->options['depth'],
            $this->options['flags']);
        if (json_last_error() > 0) {
            $data = null;
            $this->error = json_last_error_msg() ?: 'Unknown';
        }

        return $data;
    }
24034
public static function encode($data)
    {
        if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
            $json = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
        } else {
            $json = json_encode($data);
        }

        self::handleError(json_last_error());

        return $json;
    }
1352219
public function encodeArray($data) {
        $d = array();
        foreach ($data as $key => $value) {
            if (is_string($key))
                $key = htmlspecialchars($key);
            if (is_string($value))
                $value = htmlspecialchars($value);
            elseif (is_array($value))
                $value = self::encodeArray($value);
            $d[$key] = $value;
        }
        return $d;
    }
1182029
protected function convertValue($data)
    {
        if ($this->isTraversable($data)) {
            return $this->recursiveConvertArray($data);
        }

        if (is_object($data)) {
            return $this->convertObject($data) ?: null;
        }

        return $data;
    }
406526
public static function maybeSerialize($data)
    {
        if (is_array($data) || is_object($data)) {
            return @serialize($data);
        }

        // Double serialization is required for backward compatibility.
        if (static::isSerialized($data, false)) {
            return serialize($data);
        }

        return $data;
    }
1087833
public function encode($data)
    {
        // skip empty strings
        if ($data === '') {
            return '""';
        }

        $data = json_encode($data, $this->options['flags'], $this->options['depth']);
        if (json_last_error() > 0) {
            $data = null;
            $this->error = json_last_error_msg() ?: 'Unknown';
        }

        return $data;
    }
344705
static public function decode($data)
	{
	    return json_decode($data, true) ? : ($data && $data!='\"\"' && $data !='false' ? $data : null);
	}
72342
protected function postSerialization(array &$data)
    {
        RecursiveDeleteHelper::deleteKeys($data, [Serializer::CLASS_IDENTIFIER_KEY]);
        RecursiveDeleteHelper::deleteKeys($data, [Serializer::MAP_TYPE]);
        RecursiveFormatterHelper::formatScalarValues($data);
        AttributeFormatterHelper::flattenObjectsWithSingleKeyScalars($data);
        $this->recursiveSetKeysToUnderScore($data);
        $this->setResponseMeta($data);

        return $data;
    }
890723
private function doEncode($data = null)
    {
        $data = is_null($data) ? $this->data : $data;

        if (is_array($data) && (isset ($data[0]) || empty ($data))) {
            return $this->encodeList($data);
        } elseif (is_array($data)) {
            return $this->encodeDict($data);
        } elseif (is_integer($data) || is_float($data)) {
            $data = sprintf("%.0f", round($data, 0));
            return $this->encodeInteger($data);
        } else {
            return $this->encodeString($data);
        }
    }
874439
public static function encode($data)
    {
        if (!is_string($data)) {
            throw new InvalidArgumentException('data must be string');
        }

        $encodedData = parent::encode($data);

        // URL safe replacement and remove padding
        return rtrim(strtr($encodedData, '+/', '-_'), '=');
    }
657827
public static function is_serialized($data)
    {
        // If it isn't a string, it isn't serialized
        if (!is_string($data)) {
            return false;
        }

        $data = trim($data);

        // Is it the serialized NULL value?
        if ($data === 'N;') {
            return true;
        } elseif ($data === 'b:0;' || $data === 'b:1;') {
            // Is it a serialized boolean?
            return true;
        }

        $length = strlen($data);

        // Check some basic requirements of all serialized strings
        if ($length < 4 || $data[1] !== ':' || ($data[$length - 1] !== ';' && $data[$length - 1] !== '}')) {
            return false;
        }

        return @unserialize($data) !== false;
    }
160374
public function encode($data)
    {
        if ($data !== null) {
            $data = gzencode((string) $data, $this->options['level'], $this->options['mode']);
            if ($data === false) {
                $data = null;
                $this->error = error_get_last()['message'] ?? 'Unknown';
            }
        }

        return $data;
    }
220785
public static function encodePhp( array $data ) {
		$ret = '';
		foreach ( $data as $key => $value ) {
			if ( strcmp( $key, intval( $key ) ) === 0 ) {
				self::$logger->warning( "Ignoring unsupported integer key \"$key\"" );
				continue;
			}
			if ( strcspn( $key, '|!' ) !== strlen( $key ) ) {
				self::$logger->error( "Serialization failed: Key with unsupported characters \"$key\"" );
				return null;
			}
			$v = self::serializeValue( $value );
			if ( $v === null ) {
				return null;
			}
			$ret .= "$key|$v";
		}
		return $ret;
	}