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 0ff8404

Browse filesBrowse files
praadjaviereguiluz
authored andcommitted
[Serializer] Update serializer.rst
1 parent 1119568 commit 0ff8404
Copy full SHA for 0ff8404

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.