Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit dd3a32e

Browse filesBrowse files
committed
minor #20479 [Serializer] Update serializer.rst (praad)
This PR was submitted for the 7.2 branch but it was squashed and merged into the 6.4 branch instead. Discussion ---------- [Serializer] Update serializer.rst Usable example for standalone using of ArrayDenormalizator <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/releases for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `7.x` for features of unreleased versions). --> Commits ------- 0ff8404 [Serializer] Update serializer.rst
2 parents 1119568 + 0ff8404 commit dd3a32e
Copy full SHA for dd3a32e

File tree

Expand file treeCollapse file tree

1 file changed

+25
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+25
-0
lines changed

‎serializer.rst

Copy file name to clipboardExpand all lines: serializer.rst
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,31 @@ normalizers (in order of priority):
13521352
This denormalizer converts an array of arrays to an array of objects
13531353
(with the given type). See :ref:`Handling Arrays <serializer-handling-arrays>`.
13541354

1355+
ByUsing the PropertyInfoExtractor you can simply annotate the arrays by '@var Person[]'
1356+
1357+
.. configuration-block::
1358+
1359+
.. code-block:: php-standalone
1360+
1361+
use Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor;
1362+
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
1363+
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
1364+
use Symfony\Component\Serializer\Encoder\JsonEncoder;
1365+
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
1366+
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;
1367+
use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer;
1368+
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
1369+
use Symfony\Component\Serializer\Serializer;
1370+
1371+
$reflectionExtractor = new ReflectionExtractor();
1372+
$phpDocExtractor = new PhpDocExtractor();
1373+
$propertyInfo = new PropertyInfoExtractor([], [$phpDocExtractor, $reflectionExtractor]);
1374+
1375+
$classMetadataFactory = new ClassMetadataFactory(new AttributeLoader());
1376+
$normalizers = [new ObjectNormalizer($classMetadataFactory, null, null, $propertyInfo), new ArrayDenormalizer()];
1377+
1378+
$this->serializer = new Serializer($normalizers, [new JsonEncoder()]);
1379+
13551380
:class:`Symfony\\Component\\Serializer\\Normalizer\\ObjectNormalizer`
13561381
This is the most powerful default normalizer and used for any object
13571382
that could not be normalized by the other normalizers.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.