Skip to content

Commit 290cfae

Browse files
committed
[Serializer] Minor improvements
1 parent a798057 commit 290cfae

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

serializer.rst

+11-5
Original file line numberDiff line numberDiff line change
@@ -958,16 +958,22 @@ parameter::
958958
$jsonData = ...; // the serialized JSON data from the previous example
959959
$persons = $serializer->deserialize($JsonData, Person::class.'[]', 'json');
960960

961-
For nested classes, you have to add a PHPDoc type to the property/setter::
961+
For nested classes, you have to add a PHPDoc type to the property, constructor or setter::
962962

963963
// src/Model/UserGroup.php
964964
namespace App\Model;
965965

966966
class UserGroup
967967
{
968-
private array $members;
968+
/**
969+
* @param Person[] $members
970+
*/
971+
public function __construct(
972+
private array $members,
973+
) {
974+
}
969975

970-
// ...
976+
// or if you're using a setter
971977

972978
/**
973979
* @param Person[] $members
@@ -976,6 +982,8 @@ For nested classes, you have to add a PHPDoc type to the property/setter::
976982
{
977983
$this->members = $members;
978984
}
985+
986+
// ...
979987
}
980988

981989
.. tip::
@@ -1357,8 +1365,6 @@ normalizers (in order of priority):
13571365
During denormalization, it supports using the constructor as well as
13581366
the discovered methods.
13591367

1360-
:ref:`serializer.encoder <reference-dic-tags-serializer-encoder>`
1361-
13621368
.. danger::
13631369

13641370
Always make sure the ``DateTimeNormalizer`` is registered when

serializer/encoders.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,8 @@ as a service in your app. If you're using the
311311
that's done automatically!
312312

313313
If you're not using :ref:`autoconfigure <services-autoconfigure>`, make sure
314-
to register your class as a service and tag it with ``serializer.encoder``:
314+
to register your class as a service and tag it with
315+
:ref:`serializer.encoder <reference-dic-tags-serializer-encoder>`:
315316

316317
.. configuration-block::
317318

0 commit comments

Comments
 (0)