Skip to content

Commit f53d88f

Browse files
[Serializer] Deprecate annotations
1 parent 0349081 commit f53d88f

File tree

2 files changed

+42
-10
lines changed

2 files changed

+42
-10
lines changed

components/property_info.rst

+16-5
Original file line numberDiff line numberDiff line change
@@ -464,19 +464,30 @@ the :class:`Symfony\\Component\\PropertyInfo\\Extractor\\SerializerExtractor`
464464
provides list information. This extractor is *not* registered automatically
465465
with the ``property_info`` service in the Symfony Framework::
466466

467-
use Doctrine\Common\Annotations\AnnotationReader;
468467
use Symfony\Component\PropertyInfo\Extractor\SerializerExtractor;
469468
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
470-
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
469+
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;
471470

472-
$serializerClassMetadataFactory = new ClassMetadataFactory(
473-
new AnnotationLoader(new AnnotationReader)
474-
);
471+
$serializerClassMetadataFactory = new ClassMetadataFactory(new AttributeLoader());
475472
$serializerExtractor = new SerializerExtractor($serializerClassMetadataFactory);
476473

477474
// the `serializer_groups` option must be configured (may be set to null)
478475
$serializerExtractor->getProperties($class, ['serializer_groups' => ['mygroup']]);
479476

477+
.. versionadded:: 6.4
478+
479+
The
480+
:class:`Symfony\\Component\\Serializer\\Mapping\\Loader\\AttributeLoader`
481+
was introduced in Symfony 6.4. Prior to this, the
482+
:class:`Symfony\\Component\\Serializer\\Mapping\\Loader\\AnnotationLoader`
483+
must be used.
484+
485+
.. deprecated:: 6.4
486+
487+
The
488+
:class:`Symfony\\Component\\Serializer\\Mapping\\Loader\\AnnotationLoader`
489+
was deprecated in Symfony 6.4.
490+
480491
If ``serializer_groups`` is set to ``null``, serializer groups metadata won't be
481492
checked but you will get only the properties considered by the Serializer
482493
Component (notably the ``@Ignore`` annotation is taken into account).

components/serializer.rst

+26-5
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,13 @@ for each format:
279279

280280
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
281281

282+
* Attributes in PHP files::
283+
284+
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
285+
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;
286+
287+
$classMetadataFactory = new ClassMetadataFactory(new AttributeLoader());
288+
282289
* YAML files::
283290

284291
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
@@ -293,6 +300,21 @@ for each format:
293300

294301
$classMetadataFactory = new ClassMetadataFactory(new XmlFileLoader('/path/to/your/definition.xml'));
295302

303+
.. versionadded:: 6.4
304+
305+
The
306+
:class:`Symfony\\Component\\Serializer\\Mapping\\Loader\\AttributeLoader`
307+
was introduced in Symfony 6.4. Prior to this, the
308+
:class:`Symfony\\Component\\Serializer\\Mapping\\Loader\\AnnotationLoader`
309+
must be used.
310+
311+
.. deprecated:: 6.4
312+
313+
Reading annotations in PHP files is deprecated since Symfony 6.4.
314+
Also, the
315+
:class:`Symfony\\Component\\Serializer\\Mapping\\Loader\\AnnotationLoader`
316+
was deprecated in Symfony 6.4.
317+
296318
.. _component-serializer-attributes-groups-annotations:
297319
.. _component-serializer-attributes-groups-attributes:
298320

@@ -645,7 +667,7 @@ this is already set up and you only need to provide the configuration. Otherwise
645667
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
646668
use Symfony\Component\Serializer\Serializer;
647669

648-
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
670+
$classMetadataFactory = new ClassMetadataFactory(new AttributeLoader());
649671

650672
$metadataAwareNameConverter = new MetadataAwareNameConverter($classMetadataFactory);
651673

@@ -1533,10 +1555,9 @@ Instead of throwing an exception, a custom callable can be executed when the
15331555
maximum depth is reached. This is especially useful when serializing entities
15341556
having unique identifiers::
15351557

1536-
use Doctrine\Common\Annotations\AnnotationReader;
15371558
use Symfony\Component\Serializer\Annotation\MaxDepth;
15381559
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
1539-
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
1560+
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;
15401561
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
15411562
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
15421563
use Symfony\Component\Serializer\Serializer;
@@ -1560,7 +1581,7 @@ having unique identifiers::
15601581
$level3->id = 3;
15611582
$level2->child = $level3;
15621583

1563-
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
1584+
$classMetadataFactory = new ClassMetadataFactory(new AttributeLoader());
15641585

15651586
// all callback parameters are optional (you can omit the ones you don't use)
15661587
$maxDepthHandler = function (object $innerObject, object $outerObject, string $attributeName, string $format = null, array $context = []): string {
@@ -1761,7 +1782,7 @@ this is already set up and you only need to provide the configuration. Otherwise
17611782
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
17621783
use Symfony\Component\Serializer\Serializer;
17631784

1764-
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
1785+
$classMetadataFactory = new ClassMetadataFactory(new AttributeLoader());
17651786

17661787
$discriminator = new ClassDiscriminatorFromClassMetadata($classMetadataFactory);
17671788

0 commit comments

Comments
 (0)