Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

[Serializer] Deprecate annotations#19046

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletionscomponents/property_info.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -464,19 +464,30 @@ the :class:`Symfony\\Component\\PropertyInfo\\Extractor\\SerializerExtractor`
provides list information. This extractor is *not* registered automatically
with the ``property_info`` service in the Symfony Framework::

use Doctrine\Common\Annotations\AnnotationReader;
use Symfony\Component\PropertyInfo\Extractor\SerializerExtractor;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;

$serializerClassMetadataFactory = new ClassMetadataFactory(
new AnnotationLoader(new AnnotationReader)
);
$serializerClassMetadataFactory = new ClassMetadataFactory(new AttributeLoader());
$serializerExtractor = new SerializerExtractor($serializerClassMetadataFactory);

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

.. versionadded:: 6.4

The
:class:`Symfony\\Component\\Serializer\\Mapping\\Loader\\AttributeLoader`
was introduced in Symfony 6.4. Prior to this, the
:class:`Symfony\\Component\\Serializer\\Mapping\\Loader\\AnnotationLoader`
must be used.

.. deprecated:: 6.4

The
:class:`Symfony\\Component\\Serializer\\Mapping\\Loader\\AnnotationLoader`
was deprecated in Symfony 6.4.

If ``serializer_groups`` is set to ``null``, serializer groups metadata won't be
checked but you will get only the properties considered by the Serializer
Component (notably the ``@Ignore`` annotation is taken into account).
Expand Down
31 changes: 26 additions & 5 deletionscomponents/serializer.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -279,6 +279,13 @@ for each format:

$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

should be removed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

or remove it in 7.0?

Copy link
MemberAuthor

@alexandre-dauboisalexandre-dauboisOct 24, 2023
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It is still valid in 6.4 so I think itshould stay with the deprecation message below. If someone wants to migrate from one to another, this person may search forAnnotationLoader in the doc to understand how to migrate

I would remove it in 7.0 🙂

OskarStark reacted with thumbs up emoji
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Can you open a PR?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Yep 🙂


* Attributes in PHP files::

use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;

$classMetadataFactory = new ClassMetadataFactory(new AttributeLoader());

* YAML files::

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

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

.. versionadded:: 6.4

The
:class:`Symfony\\Component\\Serializer\\Mapping\\Loader\\AttributeLoader`
was introduced in Symfony 6.4. Prior to this, the
:class:`Symfony\\Component\\Serializer\\Mapping\\Loader\\AnnotationLoader`
must be used.

.. deprecated:: 6.4

Reading annotations in PHP files is deprecated since Symfony 6.4.
Also, the
:class:`Symfony\\Component\\Serializer\\Mapping\\Loader\\AnnotationLoader`
was deprecated in Symfony 6.4.

.. _component-serializer-attributes-groups-annotations:
.. _component-serializer-attributes-groups-attributes:

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

$classMetadataFactory = new ClassMetadataFactory(newAnnotationLoader(new AnnotationReader()));
$classMetadataFactory = new ClassMetadataFactory(newAttributeLoader());

$metadataAwareNameConverter = new MetadataAwareNameConverter($classMetadataFactory);

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

use Doctrine\Common\Annotations\AnnotationReader;
use Symfony\Component\Serializer\Annotation\MaxDepth;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;
Expand All@@ -1560,7 +1581,7 @@ having unique identifiers::
$level3->id = 3;
$level2->child = $level3;

$classMetadataFactory = new ClassMetadataFactory(newAnnotationLoader(new AnnotationReader()));
$classMetadataFactory = new ClassMetadataFactory(newAttributeLoader());

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

$classMetadataFactory = new ClassMetadataFactory(newAnnotationLoader(new AnnotationReader()));
$classMetadataFactory = new ClassMetadataFactory(newAttributeLoader());

$discriminator = new ClassDiscriminatorFromClassMetadata($classMetadataFactory);

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp