-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Update serializer.rst #20479
base: 7.2
Are you sure you want to change the base?
Update serializer.rst #20479
Conversation
Usable example for standalone using of ArrayDenormalizator
@param annotation not working in a Standalone instantiation according to my tests. Given example can save for others a lot of time. Feel free to modify it. Thanks. |
@@ -1344,6 +1344,31 @@ normalizers (in order of priority): | |||
This denormalizer converts an array of arrays to an array of objects | |||
(with the given type). See :ref:`Handling Arrays <serializer-handling-arrays>`. | |||
|
|||
ByUsing the PropertyInfoExtractor you can simply annotate the arrays by '@var Person[]' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ByUsing the PropertyInfoExtractor you can simply annotate the arrays by '@var Person[]' | |
By using :class:`Symfony\\Component\\PropertyInfo\\PropertyInfoExtractor` you can provide hints with annotations like `@var Person[]` |
$reflectionExtractor = new ReflectionExtractor(); | ||
$phpDocExtractor = new PhpDocExtractor(); | ||
$propertyInfo = new PropertyInfoExtractor([], [$phpDocExtractor, $reflectionExtractor]); | ||
|
||
$classMetadataFactory = new ClassMetadataFactory(new AttributeLoader()); | ||
$normalizers = [new ObjectNormalizer($classMetadataFactory, null, null, $propertyInfo), new ArrayDenormalizer()]; | ||
|
||
$this->serializer = new Serializer($normalizers, [new JsonEncoder()]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the goal of the example, I think we could provide a more compact snippet.
$reflectionExtractor = new ReflectionExtractor(); | |
$phpDocExtractor = new PhpDocExtractor(); | |
$propertyInfo = new PropertyInfoExtractor([], [$phpDocExtractor, $reflectionExtractor]); | |
$classMetadataFactory = new ClassMetadataFactory(new AttributeLoader()); | |
$normalizers = [new ObjectNormalizer($classMetadataFactory, null, null, $propertyInfo), new ArrayDenormalizer()]; | |
$this->serializer = new Serializer($normalizers, [new JsonEncoder()]); | |
$propertyInfo = new PropertyInfoExtractor([], [new PhpDocExtractor(), new ReflectionExtractor()]); | |
$normalizers = [new ObjectNormalizer(new ClassMetadataFactory(new AttributeLoader()), null, null, $propertyInfo), new ArrayDenormalizer()]; | |
$this->serializer = new Serializer($normalizers, [new JsonEncoder()]); |
Usable example for standalone using of ArrayDenormalizator