final public function Serializer::serialize

Serializes data in the appropriate format

Parameters

mixed $data any data:

string $format format name:

Return value

string

Overrides SerializerInterface::serialize

File

drupal/core/vendor/symfony/serializer/Symfony/Component/Serializer/Serializer.php, line 75

Class

Serializer
Serializer serializes and deserializes data

Namespace

Symfony\Component\Serializer

Code

public final function serialize($data, $format) {
  if (!$this
    ->supportsEncoding($format)) {
    throw new UnexpectedValueException('Serialization for the format ' . $format . ' is not supported');
  }
  if ($this->encoder
    ->needsNormalization($format)) {
    $data = $this
      ->normalize($data, $format);
  }
  return $this
    ->encode($data, $format);
}