Skip to content

Commit 727f81d

Browse files
fbourigaultdunglas
authored andcommitted
[Serialized] allow configuring the serialized name of properties through metadata
1 parent 8e84115 commit 727f81d

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@
7474
use Symfony\Component\PropertyAccess\PropertyAccessor;
7575
use Symfony\Component\PropertyInfo\PropertyAccessExtractorInterface;
7676
use Symfony\Component\PropertyInfo\PropertyDescriptionExtractorInterface;
77-
use Symfony\Component\PropertyInfo\PropertyInitializableExtractorInterface;
7877
use Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface;
78+
use Symfony\Component\PropertyInfo\PropertyInitializableExtractorInterface;
7979
use Symfony\Component\PropertyInfo\PropertyListExtractorInterface;
8080
use Symfony\Component\PropertyInfo\PropertyTypeExtractorInterface;
8181
use Symfony\Component\Routing\Loader\AnnotationDirectoryLoader;
@@ -1363,7 +1363,7 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
13631363
}
13641364

13651365
if (isset($config['name_converter']) && $config['name_converter']) {
1366-
$container->getDefinition('serializer.normalizer.object')->replaceArgument(1, new Reference($config['name_converter']));
1366+
$container->getDefinition('serializer.name_converter.metadata_aware')->setArgument(1, new Reference($config['name_converter']));
13671367
}
13681368

13691369
if (isset($config['circular_reference_handler']) && $config['circular_reference_handler']) {

Resources/config/serializer.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858

5959
<service id="serializer.normalizer.object" class="Symfony\Component\Serializer\Normalizer\ObjectNormalizer">
6060
<argument type="service" id="serializer.mapping.class_metadata_factory" />
61-
<argument>null</argument> <!-- name converter -->
61+
<argument type="service" id="serializer.name_converter.metadata_aware" />
6262
<argument type="service" id="serializer.property_accessor" />
6363
<argument type="service" id="property_info" on-invalid="ignore" />
6464
<argument type="service" id="serializer.mapping.class_discriminator_resolver" on-invalid="ignore" />
@@ -119,6 +119,10 @@
119119
<!-- Name converter -->
120120
<service id="serializer.name_converter.camel_case_to_snake_case" class="Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter" />
121121

122+
<service id="serializer.name_converter.metadata_aware" class="Symfony\Component\Serializer\NameConverter\MetadataAwareNameConverter" >
123+
<argument type="service" id="serializer.mapping.class_metadata_factory"/>
124+
</service>
125+
122126
<!-- PropertyInfo extractor -->
123127
<service id="property_info.serializer_extractor" class="Symfony\Component\PropertyInfo\Extractor\SerializerExtractor">
124128
<argument type="service" id="serializer.mapping.class_metadata_factory" />

Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ public function testSerializerEnabled()
976976
$this->assertCount(2, $argument);
977977
$this->assertEquals('Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader', $argument[0]->getClass());
978978
$this->assertNull($container->getDefinition('serializer.mapping.class_metadata_factory')->getArgument(1));
979-
$this->assertEquals(new Reference('serializer.name_converter.camel_case_to_snake_case'), $container->getDefinition('serializer.normalizer.object')->getArgument(1));
979+
$this->assertEquals(new Reference('serializer.name_converter.camel_case_to_snake_case'), $container->getDefinition('serializer.name_converter.metadata_aware')->getArgument(1));
980980
$this->assertEquals(new Reference('property_info', ContainerBuilder::IGNORE_ON_INVALID_REFERENCE), $container->getDefinition('serializer.normalizer.object')->getArgument(3));
981981
$this->assertEquals(array('setCircularReferenceHandler', array(new Reference('my.circular.reference.handler'))), $container->getDefinition('serializer.normalizer.object')->getMethodCalls()[0]);
982982
$this->assertEquals(array('setMaxDepthHandler', array(new Reference('my.max.depth.handler'))), $container->getDefinition('serializer.normalizer.object')->getMethodCalls()[1]);

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"symfony/process": "~3.4|~4.0",
4646
"symfony/security-core": "~3.4|~4.0",
4747
"symfony/security-csrf": "~3.4|~4.0",
48-
"symfony/serializer": "^4.1",
48+
"symfony/serializer": "^4.2",
4949
"symfony/stopwatch": "~3.4|~4.0",
5050
"symfony/translation": "~4.2",
5151
"symfony/templating": "~3.4|~4.0",

0 commit comments

Comments
 (0)