Copied!

Serializer serializes and deserializes data.

objects are turned into arrays by normalizers. arrays are turned into various output formats by encoders.

$serializer->serialize($obj, 'xml')
$serializer->decode($data, 'xml')
$serializer->denormalize($data, 'Class', 'xml')
CloneableInstantiable
Constants
public Symfony\Component\Serializer\Normalizer\DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS = 'collect_denormalization_errors'
public Symfony\Component\Serializer\Serializer::EMPTY_ARRAY_AS_OBJECT = 'empty_array_as_object'
 

Flag to control whether an empty array should be transformed to an object (in JSON: {}) or to a list (in JSON: []).

Methods
public __construct(array $normalizers = [], array $encoders = [], array $defaultContext = [])
 
  • param (\NormalizerInterface|\DenormalizerInterface)[] $normalizers
  • param (\EncoderInterface|\DecoderInterface)[] $encoders
  • param array<string,mixed> $defaultContext
public final decode(string $data, string $format, array $context = []) : ?mixed
public denormalize(?mixed $data, string $type, ?string $format = NULL, array $context = []) : ?mixed
 
  • throws \NotNormalizableValueException
  • throws \PartialDenormalizationException Occurs when one or more properties of $type fails to denormalize
public final deserialize(?mixed $data, string $type, string $format, array $context = []) : ?mixed
public final encode(?mixed $data, string $format, array $context = []) : string
public getSupportedTypes(?string $format) : array
public normalize(?mixed $data, ?string $format = NULL, array $context = []) : ArrayObject|array|string|int|float|bool|?null
public final serialize(?mixed $data, string $format, array $context = []) : string
public supportsDecoding(string $format, array $context = []) : bool
public supportsDenormalization(?mixed $data, string $type, ?string $format = NULL, array $context = []) : bool
public supportsEncoding(string $format, array $context = []) : bool
public supportsNormalization(?mixed $data, ?string $format = NULL, array $context = []) : bool
Constants
private Symfony\Component\Serializer\Serializer::SCALAR_TYPES = ['int' => true, 'bool' => true, 'float' => true, 'string' => true]
Properties
private array $defaultContext
private array $denormalizerCache = []
 
  • var array<string,array<string,bool[]>>
private array $normalizerCache = []
 
  • var array<string,array<string,bool[]>>
private array $normalizers
Methods
private getDenormalizer(?mixed $data, string $class, ?string $format, array $context) : ?Symfony\Component\Serializer\Normalizer\DenormalizerInterface
 

Returns a matching denormalizer.

  • param mixed $data Data to restore
  • param string $class The expected class to instantiate
  • param string|null $format Format name, present to give the option to normalizers to act differently based on formats
  • param array $context Options available to the denormalizer
private getNormalizer(?mixed $data, ?string $format, array $context) : ?Symfony\Component\Serializer\Normalizer\NormalizerInterface
 

Returns a matching normalizer.

  • param mixed $data Data to get the serializer for
  • param string|null $format Format name, present to give the option to normalizers to act differently based on formats
  • param array $context Options available to the normalizer
© 2025 Bruce Wells
Search Namespaces \ Classes
Configuration