|
33 | 33 | use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
|
34 | 34 | use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
|
35 | 35 | use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
|
| 36 | +use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter; |
36 | 37 | use Symfony\Component\Serializer\NameConverter\MetadataAwareNameConverter;
|
37 | 38 | use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
38 | 39 | use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
|
@@ -140,6 +141,20 @@ public function testDenormalizeWithNestedAttributesWithoutMetadata()
|
140 | 141 | $this->assertNull($test->notfoo);
|
141 | 142 | }
|
142 | 143 |
|
| 144 | + public function testDenormalizeWithSnakeCaseNestedAttributes() |
| 145 | + { |
| 146 | + $factory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader())); |
| 147 | + $normalizer = new AbstractObjectNormalizerDummy($factory, new CamelCaseToSnakeCaseNameConverter()); |
| 148 | + $serializer = new Serializer([$normalizer]); |
| 149 | + $data = [ |
| 150 | + 'one' => [ |
| 151 | + 'two_three' => 'fooBar', |
| 152 | + ], |
| 153 | + ]; |
| 154 | + $test = $serializer->denormalize($data, SnakeCaseNestedDummy::class, 'any'); |
| 155 | + $this->assertSame('fooBar', $test->fooBar); |
| 156 | + } |
| 157 | + |
143 | 158 | public function testDenormalizeWithNestedAttributes()
|
144 | 159 | {
|
145 | 160 | $normalizer = new AbstractObjectNormalizerWithMetadata();
|
@@ -770,7 +785,7 @@ protected function setAttributeValue(object $object, string $attribute, $value,
|
770 | 785 |
|
771 | 786 | protected function isAllowedAttribute($classOrObject, string $attribute, string $format = null, array $context = []): bool
|
772 | 787 | {
|
773 |
| - return \in_array($attribute, ['foo', 'baz', 'quux', 'value']); |
| 788 | + return \in_array($attribute, ['foo', 'baz', 'quux', 'value', 'fooBar']); |
774 | 789 | }
|
775 | 790 |
|
776 | 791 | public function instantiateObject(array &$data, string $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes, string $format = null): object
|
@@ -861,6 +876,14 @@ public function __construct(
|
861 | 876 | }
|
862 | 877 | }
|
863 | 878 |
|
| 879 | +class SnakeCaseNestedDummy |
| 880 | +{ |
| 881 | + /** |
| 882 | + * @SerializedPath("[one][two_three]") |
| 883 | + */ |
| 884 | + public $fooBar; |
| 885 | +} |
| 886 | + |
864 | 887 | /**
|
865 | 888 | * @DiscriminatorMap(typeProperty="type", mapping={
|
866 | 889 | * "first" = FirstNestedDummyWithConstructorAndDiscriminator::class,
|
|
0 commit comments