You are browsing the documentation for Symfony 2.8 which is not maintained anymore.

Consider upgrading your projects to Symfony 5.3.


2.8 version


Normalizers turn objects into arrays and vice versa. They implement Symfony\Component\Serializer\Normalizers\NormalizerInterface for normalizing (object to array) and Symfony\Component\Serializer\Normalizers\DenormalizerInterface for denormalizing (array to object).

Normalizers are enabled in the serializer passing them as its first argument:

use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;

$normalizers = array(new ObjectNormalizer());
$serializer = new Serializer($normalizers);

Built-in Normalizers

Symfony includes the following normalizers but you can also create your own normalizer:

  • Symfony\Component\Serializer\Normalizer\ObjectNormalizer to normalize PHP object using the PropertyAccessor component;
  • Symfony\Component\Serializer\Normalizer\CustomNormalizer to normalize PHP object using an object that implements :class:`Symfony\\Component\\Serializer\\Normalizer\\NormalizableInterface;
  • Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer to normalize PHP object using the getter and setter methods of the object;
  • Symfony\Component\Serializer\Normalizer\PropertyNormalizer to normalize PHP object using PHP reflection.

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.