Skip to content

Commit 44f0f13

Browse files
committed
minor #20434 [Serializer] Minor improvements (HypeMC)
This PR was merged into the 6.4 branch. Discussion ---------- [Serializer] Minor improvements Fixes/improves two things: 1. as discussed with `@wouterj` on Slack, there seems to be a leftover link to `serializer.encoder`: ![image](https://github.com/user-attachments/assets/f6fe6647-311d-4e48-9d40-f6061e640910) 2. I've added an example of how to use nested classes with a constructor to make it clear that this works as well Commits ------- 290cfae [Serializer] Minor improvements
2 parents 6e55716 + 290cfae commit 44f0f13

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

serializer.rst

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -960,16 +960,22 @@ parameter::
960960
$jsonData = ...; // the serialized JSON data from the previous example
961961
$persons = $serializer->deserialize($JsonData, Person::class.'[]', 'json');
962962

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

965965
// src/Model/UserGroup.php
966966
namespace App\Model;
967967

968968
class UserGroup
969969
{
970-
private array $members;
970+
/**
971+
* @param Person[] $members
972+
*/
973+
public function __construct(
974+
private array $members,
975+
) {
976+
}
971977

972-
// ...
978+
// or if you're using a setter
973979

974980
/**
975981
* @param Person[] $members
@@ -978,6 +984,8 @@ For nested classes, you have to add a PHPDoc type to the property/setter::
978984
{
979985
$this->members = $members;
980986
}
987+
988+
// ...
981989
}
982990

983991
.. tip::
@@ -1359,8 +1367,6 @@ normalizers (in order of priority):
13591367
During denormalization, it supports using the constructor as well as
13601368
the discovered methods.
13611369

1362-
:ref:`serializer.encoder <reference-dic-tags-serializer-encoder>`
1363-
13641370
.. danger::
13651371

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

serializer/encoders.rst

Lines changed: 2 additions & 1 deletion
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)