-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Serializer] Selecting a particular Normalizer to use? #18066
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@dunglas Maybe you can confirm if this 👇🏻 is the way to go? <?php
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Serializer\Normalizer\PropertyNormalizer;
class MyBlogPostNormalizer implements NormalizerInterface
{
public function __construct(private readonly PropertyNormalizer $propertyNormalizer)
{
}
public function normalize(mixed $object, string $format = null, array $context = [])
{
return $this->propertyNormalizer->normalize($object, $format, $context);
}
public function supportsNormalization(mixed $data, string $format = null): bool
{
return $data instanceof DateRange;
}
} |
I think this is something that should be addressed to discussions. However, what I can tell is this is not the solution because injecting ObjectNormalizer and PropertyNormalizer is deprecated since 6.2. You may instantiate PropertyNormalizer manually though (but you cannot extend it as it was made final in 6.3) |
Thank you for this issue. |
Could I get an answer? If I do not hear anything I will assume this issue is resolved or abandoned. Please get back to me <3 |
Hey, I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen! |
Hi there,
the documentation lists many different normalizers that are supported out of the box and – to my understanding – active by default when using the full stack framework.
But one question I am facing right now seems to be unanswered: Can I (how?) choose a particular normalizer for a given class?
Say, I have a
MyBlogPost
class that is included in data to be serialized, and I want thePropertyNormalizer
to be used for it, not theObjectNormalizer
.What is the recommended way to do this? I can try to write the docs, but need initial guidance.
Re. #17912 – are contributions for this section still pending the revamp?
The text was updated successfully, but these errors were encountered: