|
17 | 17 | use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
|
18 | 18 | use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
|
19 | 19 | use Symfony\Component\PropertyInfo\Type;
|
| 20 | +use Symfony\Component\Serializer\Annotation\SerializedName; |
20 | 21 | use Symfony\Component\Serializer\Exception\ExtraAttributesException;
|
21 | 22 | use Symfony\Component\Serializer\Exception\InvalidArgumentException;
|
22 | 23 | use Symfony\Component\Serializer\Exception\LogicException;
|
|
30 | 31 | use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
|
31 | 32 | use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
|
32 | 33 | use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
|
| 34 | +use Symfony\Component\Serializer\NameConverter\MetadataAwareNameConverter; |
33 | 35 | use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
34 | 36 | use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
|
35 | 37 | use Symfony\Component\Serializer\Normalizer\CustomNormalizer;
|
@@ -658,6 +660,34 @@ protected function createChildContext(array $parentContext, string $attribute, ?
|
658 | 660 |
|
659 | 661 | $this->assertFalse($normalizer->childContextCacheKey);
|
660 | 662 | }
|
| 663 | + |
| 664 | + public function testDenormalizeXmlScalar() |
| 665 | + { |
| 666 | + $normalizer = new class () extends AbstractObjectNormalizer |
| 667 | + { |
| 668 | + public function __construct() |
| 669 | + { |
| 670 | + parent::__construct(null, new MetadataAwareNameConverter(new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader())))); |
| 671 | + } |
| 672 | + |
| 673 | + protected function extractAttributes(object $object, string $format = null, array $context = []): array |
| 674 | + { |
| 675 | + return []; |
| 676 | + } |
| 677 | + |
| 678 | + protected function getAttributeValue(object $object, string $attribute, string $format = null, array $context = []) |
| 679 | + { |
| 680 | + return null; |
| 681 | + } |
| 682 | + |
| 683 | + protected function setAttributeValue(object $object, string $attribute, $value, string $format = null, array $context = []) |
| 684 | + { |
| 685 | + $object->$attribute = $value; |
| 686 | + } |
| 687 | + }; |
| 688 | + |
| 689 | + $this->assertSame('scalar', $normalizer->denormalize('scalar', XmlScalarDummy::class, 'xml')->value); |
| 690 | + } |
661 | 691 | }
|
662 | 692 |
|
663 | 693 | class AbstractObjectNormalizerDummy extends AbstractObjectNormalizer
|
@@ -781,6 +811,12 @@ class DummyChild
|
781 | 811 | public $bar;
|
782 | 812 | }
|
783 | 813 |
|
| 814 | +class XmlScalarDummy |
| 815 | +{ |
| 816 | + /** @SerializedName("#") */ |
| 817 | + public $value; |
| 818 | +} |
| 819 | + |
784 | 820 | class SerializerCollectionDummy implements SerializerInterface, DenormalizerInterface
|
785 | 821 | {
|
786 | 822 | private $normalizers;
|
|
0 commit comments