Serialize data

@param mixed  $data   the data to serialize
@param string $type   the OpenAPIToolsType of the data
@param string $format the format of the OpenAPITools type of the data

@return string|object serialized form of $data
551030
public static function sanitizeForSerialization($data, $type = null, $format = null)
    {
        if (is_scalar($data) || null === $data) {
            return $data;
        } elseif ($data instanceof \DateTime) {
            return ($format === 'date') ? $data->format('Y-m-d') : $data->format(\DateTime::ATOM);
        } elseif (is_array($data)) {
            foreach ($data as $property => $value) {
                $data[$property] = self::sanitizeForSerialization($value);
            }
            return $data;
        } elseif (is_object($data)) {
            $values = [];
            $formats = $data::openAPIFormats();
            foreach ($data::openAPITypes() as $property => $openAPIType) {
                $getter = $data::getters()[$property];
                $value = $data->$getter();
                if ($value !== null
                    && !in_array($openAPIType, ['DateTime', 'bool', 'boolean', 'byte', 'double', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)
                    && method_exists($openAPIType, 'getAllowableEnumValues')
                    && !in_array($value, $openAPIType::getAllowableEnumValues(), true)) {
                    $imploded = implode("', '", $openAPIType::getAllowableEnumValues());
                    throw new \InvalidArgumentException("Invalid value for enum '$openAPIType', must be one of: '$imploded'");
                }
                if ($value !== null) {
                    $values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($value, $openAPIType, $formats[$property]);
                }
            }
            return (object)$values;
        } else {
            return (string)$data;
        }
    }
1080095
public function serialize($data, array $params = array())
    {
        return $this->jms->serialize(
            $data,
            self::SERIALIZER_FORMAT,
            $this->determineContext($this->jmsSerializeContext, $params)
        );
    }
676705
private function contentFromData($data, $format)
	{
		$type = gettype($data);
		if($type === 'string')
		{
			$content = $data;
		}
		else if($type === 'array')
		{
			switch ($format) 
			{
				case 'json':
				case 'jsonp':
					$content = json_encode($data);
					break;
				default:
					$content = serialize($data);
					break;
			}
			if($format === 'jsonp')
			{
				$customData = ('string' === gettype($this->customData)) ? $this->customData : 'data';
				if(!empty($_GET))
				{
					$getKeys = array_keys($_GET);
					$customData = $getKeys[0];
				}
				$customData = trim($customData);
				$content = $customData . '(' . $content . ');';
			}
		}
		else 
		{
			$content = serialize($data);
		}
		return $content;
	}
710141
function serialize(array $data) {
        $preSerialized = array();
        $serialized = '';

        if (count($data)) {
            foreach ($data as $bucket => $bucketData) {
                $preSerialized[] = $bucket . '|' . serialize($bucketData);
            }
            $serialized = implode('', $preSerialized);
        }

        return $serialized;
    }
483408
public function supportsNormalization($data, $format = null): bool
    {
        if (true === \is_object($data))
        {
            $class = \get_class($data);

            if (false === isset($this->localStorage[$class]))
            {
                $this->localStorage[$class] = \array_map(
                    static function(\ReflectionProperty $property): string
                    {
                        return (string) $property->name;
                    },
                    (new \ReflectionClass($data))->getProperties()
                );
            }

            return empty($this->localStorage[$class]);
        }

        return false;
    }
154988
protected function _format($type) {
        $response = array(
            'success' => $this->_success,
            'data' => $this->_data
        );

        if ($this->_code) {
            $response['code'] = $this->_code;
        }

        switch (strtolower($type)) {
            case 'json':
                $format = TypeConverter::toJson($response);
            break;
            case 'xml':
                $format = TypeConverter::toXml($response);
            break;
            case 'html';
            case 'text':
            default:
                $format = (string) $this->_data;
            break;
        }

        return $format;
    }
261818
private function parseDates($data, $format)
    {
        foreach ($data as $key => $entry) {
            $data[$key]['date'] = $data[$key]['date']->format($format);
        }

        return $data;
    }
1374908
public function jsonSerialize($format = self::JSON_DEFAULT_FORMAT)
    {
        $data = [
            'uid'        => $this->_uid,
            'label'      => $this->_label,
            'type'       => $this->getContentType(),
            'state'      => $this->_state,
            'created'    => $this->_created->getTimestamp(),
            'modified'   => $this->_modified->getTimestamp(),
            'revision'   => $this->_revision,
            'parameters' => $this->getAllParams(),
            'accept'     => array_map(
                function ($classname) {
                    return str_replace(NAMESPACE_SEPARATOR, '/', $classname);
                },
                self::getShortClassname($this->getAccept())
            ),
            'minentry'   => $this->getMinEntry(),
            'maxentry'   => $this->getMaxEntry(),
            'elements'   => $this->computeElementsToJson($this->getData()),
            'has_elements' => count($this->getData()) === 0 ? false : true,
            'extra'      => [],
        ];

        if (0 === count($data['parameters'])) {
            $data['parameters'] = new \ArrayObject();
        }

        return $this->formatJsonData($data, $format);
    }
716411
function __serializeType(type, options) {
	let typeHeader = (type) ? TYPE_HEADER[type.toUpperCase()] : [];
	let typeData = new Uint8Array(typeHeader);
	return typeData.buffer;
}
1131161
public function format($data, $format)
    {
        // Case handing. ex. json => Json
        $format = ucfirst(strtolower($format));
        $formatFunc = "format" . $format;
        // Use formatter if exists
        if (method_exists($this, $formatFunc)) {
            
            $data = $this->{$formatFunc}($data);
        } 
        elseif (is_array($data)) {
            // Use JSON while the Formatter not found and the data is array
            $data = $this->formatJson($data);
        }

        return $data;
    }
764106
protected function serialize($data, $group = self::SERIALIZE_FULL)
    {
        return $this->get('serializer')->serialize($data, 'json', ['groups' => [$group]]);
    }
1187526
def serialize(self, data):
        '''
        
        '''
        self.set_header('Content-Type', self.content_type)

        return self.dumper(data)
148574
public function decode($data, $format, array $context = array())
    {
        if ($this->native) {
            return yaml_parse($data);
        }

        return $this->decoder->parse($data);
    }
550213
public function export($format = FilledFormExportFormat::JSON)
    {
        if (! $format instanceof FilledFormExportFormat) {
            $format = new FilledFormExportFormat($format);
        }

        return static::query($this->client, [$this->filled_form_id, self::EXPORT], ['format' => $format->getValue()]);
    }
466522
protected function applyCustomFormat($format, $data)
    {
        $aClassFunc = $this->getFuncParams($format);

        $params = array_key_exists(
            'params',
            $format
        ) ? $format['params'] : [];

        array_unshift($params, $data);

        $object = (new \ReflectionClass($aClassFunc['class']))->newInstance();

        $data = call_user_func_array([$object, $aClassFunc['method']], $params);

        return $data;
    }
580835
public function encode($data): string
    {
        try {
            $data = \serialize($data);
        } catch (\Throwable $exception) {
            throw new SerializationException(
                "The given data cannot be sent because it is not serializable.",
                0,
                $exception
            );
        }

        return \pack("CL", 0, \strlen($data)) . $data;
    }
1349629
public function to_serialized($data = null)
	{
		if ($data === null)
		{
			$data = $this->_data;
		}

		return serialize($data);
	}