What is a normalizer in Symfony Serializer?
2 June 2022 (Updated 6 June 2022)
On this page
In a nutshell
A normalizer is a class that converts PHP objects into PHP arrays and vice-versa. It implements the NormalizerInterface
for normalizing (object to array), and the DenormalizerInterface
for denormalizing (array to object).
You enable a normalizer in a serializer by passing it as the first argument:
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;
$normalizers = [new ObjectNormalizer()];
$serializer = new Serializer($normalizers, []);
Built-in normalizers
The Symfony Serializer component provides several built-in normalizers.
Sources
Tagged:
Symfony
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment