Skip to content

Commit

Permalink
feature #51470 [FrameworkBundle][Serializer] Deprecate annotations (a…
Browse files Browse the repository at this point in the history
…lexandre-daubois)

This PR was merged into the 6.4 branch.

Discussion
----------

[FrameworkBundle][Serializer] Deprecate annotations

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | yes
| Tickets       | -
| License       | MIT
| Doc PR        | -

Part of #51381

Commits
-------

a658692 [FrameworkBundle][Serializer] Deprecate annotations
  • Loading branch information
nicolas-grekas committed Oct 17, 2023
2 parents 1469612 + a658692 commit c817241
Show file tree
Hide file tree
Showing 27 changed files with 440 additions and 386 deletions.
2 changes: 1 addition & 1 deletion UPGRADE-6.4.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ Serializer
----------

* Deprecate Doctrine annotations support in favor of native attributes
* Deprecate passing an annotation reader to the constructor of `AnnotationLoader`
* Deprecate `AnnotationLoader`, use `AttributeLoader` instead

Templating
----------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Encoder\YamlEncoder;
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\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;
use Twig\Environment;
Expand Down Expand Up @@ -49,7 +49,7 @@ public static function serializerDataProvider(): \Generator

private function getTwig(string $template): Environment
{
$meta = new ClassMetadataFactory(new AnnotationLoader());
$meta = new ClassMetadataFactory(new AttributeLoader());
$runtime = new SerializerRuntime(new Serializer([new ObjectNormalizer($meta)], [new JsonEncoder(), new YamlEncoder()]));

$mockRuntimeLoader = $this->createMock(RuntimeLoaderInterface::class);
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bridge/Twig/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"symfony/security-core": "^5.4|^6.0|^7.0",
"symfony/security-csrf": "^5.4|^6.0|^7.0",
"symfony/security-http": "^5.4|^6.0|^7.0",
"symfony/serializer": "^6.2|^7.0",
"symfony/serializer": "^6.4|^7.0",
"symfony/stopwatch": "^5.4|^6.0|^7.0",
"symfony/console": "^5.4|^6.0|^7.0",
"symfony/expression-language": "^5.4|^6.0|^7.0",
Expand All @@ -61,7 +61,7 @@
"symfony/http-foundation": "<5.4",
"symfony/http-kernel": "<6.4",
"symfony/mime": "<6.2",
"symfony/serializer": "<6.2",
"symfony/serializer": "<6.4",
"symfony/translation": "<5.4",
"symfony/workflow": "<5.4"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
use Symfony\Component\Semaphore\Store\StoreFactory as SemaphoreStoreFactory;
use Symfony\Component\Serializer\Encoder\DecoderInterface;
use Symfony\Component\Serializer\Encoder\EncoderInterface;
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;
use Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader;
use Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
Expand Down Expand Up @@ -1932,7 +1932,7 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
$serializerLoaders = [];
if (isset($config['enable_attributes']) && $config['enable_attributes']) {
$annotationLoader = new Definition(
AnnotationLoader::class,
AttributeLoader::class,
[new Reference('annotation_reader', ContainerInterface::NULL_ON_INVALID_REFERENCE)]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
use Symfony\Component\Notifier\TexterInterface;
use Symfony\Component\PropertyAccess\PropertyAccessor;
use Symfony\Component\Security\Core\AuthenticationEvents;
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;
use Symfony\Component\Serializer\Mapping\Loader\XmlFileLoader;
use Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader;
use Symfony\Component\Serializer\Normalizer\ConstraintViolationListNormalizer;
Expand Down Expand Up @@ -1489,7 +1489,7 @@ public function testSerializerEnabled()
$argument = $container->getDefinition('serializer.mapping.chain_loader')->getArgument(0);

$this->assertCount(2, $argument);
$this->assertEquals(AnnotationLoader::class, $argument[0]->getClass());
$this->assertEquals(AttributeLoader::class, $argument[0]->getClass());
$this->assertEquals(new Reference('serializer.name_converter.camel_case_to_snake_case'), $container->getDefinition('serializer.name_converter.metadata_aware')->getArgument(1));
$this->assertEquals(new Reference('property_info', ContainerBuilder::IGNORE_ON_INVALID_REFERENCE), $container->getDefinition('serializer.normalizer.object')->getArgument(3));
$this->assertArrayHasKey('circular_reference_handler', $container->getDefinition('serializer.normalizer.object')->getArgument(6));
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/SecurityBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"symfony/ldap": "^5.4|^6.0|^7.0",
"symfony/process": "^5.4|^6.0|^7.0",
"symfony/rate-limiter": "^5.4|^6.0|^7.0",
"symfony/serializer": "^5.4|^6.0|^7.0",
"symfony/serializer": "^6.4|^7.0",
"symfony/translation": "^5.4|^6.0|^7.0",
"symfony/twig-bundle": "^5.4|^6.0|^7.0",
"symfony/twig-bridge": "^5.4|^6.0|^7.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpKernel/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"symfony/translation": "<5.4",
"symfony/translation-contracts": "<2.5",
"symfony/twig-bridge": "<5.4",
"symfony/validator": "<5.4",
"symfony/validator": "<6.4",
"symfony/var-dumper": "<6.3",
"twig/twig": "<2.13"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy;
use Symfony\Component\PropertyInfo\Tests\Fixtures\IgnorePropertyDummy;
use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;

/**
* @author Kévin Dunglas <dunglas@gmail.com>
Expand All @@ -28,7 +28,7 @@ class SerializerExtractorTest extends TestCase

protected function setUp(): void
{
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader());
$classMetadataFactory = new ClassMetadataFactory(new AttributeLoader());
$this->extractor = new SerializerExtractor($classMetadataFactory);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/PropertyInfo/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"symfony/string": "^5.4|^6.0|^7.0"
},
"require-dev": {
"symfony/serializer": "^5.4|^6.0|^7.0",
"symfony/serializer": "^6.4|^7.0",
"symfony/cache": "^5.4|^6.0|^7.0",
"symfony/dependency-injection": "^5.4|^6.0|^7.0",
"phpdocumentor/reflection-docblock": "^5.2",
Expand All @@ -37,7 +37,7 @@
"phpdocumentor/reflection-docblock": "<5.2",
"phpdocumentor/type-resolver": "<1.5.1",
"symfony/dependency-injection": "<5.4",
"symfony/serializer": "<5.4"
"symfony/serializer": "<6.4"
},
"autoload": {
"psr-4": { "Symfony\\Component\\PropertyInfo\\": "" },
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Serializer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ CHANGELOG

* Allow `Context` attribute to target classes
* Deprecate Doctrine annotations support in favor of native attributes
* Deprecate passing an annotation reader to the constructor of `AnnotationLoader`
* Allow the `Groups` attribute/annotation on classes
* JsonDecode: Add `json_decode_detailed_errors` option
* Make `ProblemNormalizer` give details about Messenger's `ValidationFailedException`
* Add `XmlEncoder::CDATA_WRAPPING` context option
* Deprecate `AnnotationLoader`, use `AttributeLoader` instead

6.3
---
Expand Down

0 comments on commit c817241

Please sign in to comment.