Normalizers¶
Normalizers turn objects into arrays and vice versa. They implement
NormalizerInterface
for
normalizing (object to array) and
DenormalizerInterface
for
denormalizing (array to object).
Normalizers are enabled in the serializer passing them as its first argument:
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;
$normalizers = [new ObjectNormalizer()];
$serializer = new Serializer($normalizers);
Built-in Normalizers¶
Symfony includes the following normalizers but you can also create your own normalizer:
ObjectNormalizer
to normalize PHP object using the PropertyAccessor component;DateTimeZoneNormalizer
forDateTimeZone
objectsDateTimeNormalizer
for objects implementing theDateTimeInterface
interfaceDateIntervalNormalizer
forDateInterval
objectsDataUriNormalizer
to transformSplFileInfo
objects in Data URIsCustomNormalizer
to normalize PHP object using an object that implementsNormalizableInterface
;GetSetMethodNormalizer
to normalize PHP object using the getter and setter methods of the object;PropertyNormalizer
to normalize PHP object using PHP reflection.ConstraintViolationListNormalizer
for objects implementing theConstraintViolationListInterface
interfaceProblemNormalizer
forFlattenException
objectsJsonSerializableNormalizer
to deal with objects implementing theJsonSerializable
interface