@@ -12,25 +12,25 @@ Creating a New Normalizer
12
12
Imagine you want add, modify, or remove some properties during the serialization
13
13
process. For that you'll have to create your own normalizer. But it's usually
14
14
preferable 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
17
17
you access to a ``$normalizer `` property which takes care of most of the
18
18
normalization process::
19
19
20
20
// src/Serializer/TopicNormalizer.php
21
21
namespace App\Serializer;
22
22
23
23
use App\Entity\Topic;
24
+ use Symfony\Component\DependencyInjection\Attribute\Autowire;
24
25
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
25
- use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
26
- use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
27
26
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
28
27
29
- class TopicNormalizer implements NormalizerInterface, NormalizerAwareInterface
28
+ class TopicNormalizer implements NormalizerInterface
30
29
{
31
- use NormalizerAwareTrait;
32
-
33
30
public function __construct(
31
+ #[Autowire(service: 'serializer.normalizer.object')]
32
+ private readonly NormalizerInterface $normalizer,
33
+
34
34
private UrlGeneratorInterface $router,
35
35
) {
36
36
}
0 commit comments