@@ -12,25 +12,25 @@ Creating a New Normalizer
1212Imagine you want add, modify, or remove some properties during the serialization
1313process. For that you'll have to create your own normalizer. But it's usually
1414preferable to let Symfony normalize the object, then hook into the normalization
15- to customize the normalized data. To do that, leverage the
16- ``NormalizerAwareInterface `` and the `` NormalizerAwareTrait `` . This will give
15+ to customize the normalized data. To do that, you can inject a
16+ ``NormalizerInterface `` and wire it to Symfony's object normalizer . This will give
1717you access to a ``$normalizer `` property which takes care of most of the
1818normalization process::
1919
2020 // src/Serializer/TopicNormalizer.php
2121 namespace App\Serializer;
2222
2323 use App\Entity\Topic;
24+ use Symfony\Component\DependencyInjection\Attribute\Autowire;
2425 use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
25- use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
26- use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
2726 use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
2827
29- class TopicNormalizer implements NormalizerInterface, NormalizerAwareInterface
28+ class TopicNormalizer implements NormalizerInterface
3029 {
31- use NormalizerAwareTrait;
32-
3330 public function __construct(
31+ #[Autowire(service: 'serializer.normalizer.object')]
32+ private readonly NormalizerInterface $normalizer,
33+
3434 private UrlGeneratorInterface $router,
3535 ) {
3636 }
0 commit comments