final public function Serializer::serialize

Serializes data in the appropriate format

Parameters

mixed $data any data:

string $format format name:

array $context options normalizers/encoders have access to:

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, array $context = array()) {
  if (!$this
    ->supportsEncoding($format)) {
    throw new UnexpectedValueException(sprintf('Serialization for the format %s is not supported', $format));
  }
  if ($this->encoder
    ->needsNormalization($format)) {
    $data = $this
      ->normalize($data, $format, $context);
  }
  return $this
    ->encode($data, $format, $context);
}