File tree Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Expand file tree Collapse file tree 1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -12,21 +12,24 @@ 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 ``ObjectNormalizer ``::
15
+ to customize the normalized data. To do that, leverage the
16
+ ``NormalizerAwareInterface `` and the ``NormalizerAwareTrait ``. This will give
17
+ you access to a ``$normalizer `` property which takes care of most of the
18
+ normalization process::
16
19
17
20
// src/Serializer/TopicNormalizer.php
18
21
namespace App\Serializer;
19
22
20
23
use App\Entity\Topic;
21
24
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
22
25
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
23
- use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
24
26
25
- class TopicNormalizer implements NormalizerInterface
27
+ class TopicNormalizer implements NormalizerInterface, NormalizerAwareInterface
26
28
{
29
+ use NormalizerAwareTrait;
30
+
27
31
public function __construct(
28
32
private UrlGeneratorInterface $router,
29
- private ObjectNormalizer $normalizer,
30
33
) {
31
34
}
32
35
You can’t perform that action at this time.
0 commit comments