|
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;
|
@@ -548,6 +550,34 @@ public function testDenormalizeUntypedStringObject()
|
548 | 550 | $this->assertEquals(new DummyWithStringObject(new DummyString()), $actual);
|
549 | 551 | $this->assertEquals('', $actual->value->value);
|
550 | 552 | }
|
| 553 | + |
| 554 | + public function testDenormalizeXmlScalar() |
| 555 | + { |
| 556 | + $normalizer = new class () extends AbstractObjectNormalizer |
| 557 | + { |
| 558 | + public function __construct() |
| 559 | + { |
| 560 | + parent::__construct(null, new MetadataAwareNameConverter(new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader())))); |
| 561 | + } |
| 562 | + |
| 563 | + protected function extractAttributes(object $object, string $format = null, array $context = []): array |
| 564 | + { |
| 565 | + return []; |
| 566 | + } |
| 567 | + |
| 568 | + protected function getAttributeValue(object $object, string $attribute, string $format = null, array $context = []) |
| 569 | + { |
| 570 | + return null; |
| 571 | + } |
| 572 | + |
| 573 | + protected function setAttributeValue(object $object, string $attribute, $value, string $format = null, array $context = []) |
| 574 | + { |
| 575 | + $object->$attribute = $value; |
| 576 | + } |
| 577 | + }; |
| 578 | + |
| 579 | + $this->assertSame('scalar', $normalizer->denormalize('scalar', XmlScalarDummy::class, 'xml')->value); |
| 580 | + } |
551 | 581 | }
|
552 | 582 |
|
553 | 583 | class AbstractObjectNormalizerDummy extends AbstractObjectNormalizer
|
@@ -671,6 +701,12 @@ class DummyChild
|
671 | 701 | public $bar;
|
672 | 702 | }
|
673 | 703 |
|
| 704 | +class XmlScalarDummy |
| 705 | +{ |
| 706 | + /** @SerializedName("#") */ |
| 707 | + public $value; |
| 708 | +} |
| 709 | + |
674 | 710 | class SerializerCollectionDummy implements SerializerInterface, DenormalizerInterface
|
675 | 711 | {
|
676 | 712 | private $normalizers;
|
|
0 commit comments