|
18 | 18 | use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
|
19 | 19 | use Symfony\Component\PropertyInfo\Type;
|
20 | 20 | use Symfony\Component\Serializer\Annotation\Ignore;
|
| 21 | +use Symfony\Component\Serializer\Annotation\SerializedName; |
21 | 22 | use Symfony\Component\Serializer\Exception\ExtraAttributesException;
|
22 | 23 | use Symfony\Component\Serializer\Exception\InvalidArgumentException;
|
23 | 24 | use Symfony\Component\Serializer\Exception\LogicException;
|
|
31 | 32 | use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactory;
|
32 | 33 | use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface;
|
33 | 34 | use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
|
| 35 | +use Symfony\Component\Serializer\NameConverter\MetadataAwareNameConverter; |
34 | 36 | use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
|
35 | 37 | use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
|
36 | 38 | use Symfony\Component\Serializer\Normalizer\CustomNormalizer;
|
@@ -516,6 +518,34 @@ public function testDenormalizeUntypedStringObject()
|
516 | 518 | $this->assertEquals(new DummyWithStringObject(new DummyString()), $actual);
|
517 | 519 | $this->assertEquals('', $actual->value->value);
|
518 | 520 | }
|
| 521 | + |
| 522 | + public function testDenormalizeXmlScalar() |
| 523 | + { |
| 524 | + $normalizer = new class () extends AbstractObjectNormalizer |
| 525 | + { |
| 526 | + public function __construct() |
| 527 | + { |
| 528 | + parent::__construct(null, new MetadataAwareNameConverter(new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader())))); |
| 529 | + } |
| 530 | + |
| 531 | + protected function extractAttributes(object $object, string $format = null, array $context = []): array |
| 532 | + { |
| 533 | + return []; |
| 534 | + } |
| 535 | + |
| 536 | + protected function getAttributeValue(object $object, string $attribute, string $format = null, array $context = []) |
| 537 | + { |
| 538 | + return null; |
| 539 | + } |
| 540 | + |
| 541 | + protected function setAttributeValue(object $object, string $attribute, $value, string $format = null, array $context = []) |
| 542 | + { |
| 543 | + $object->$attribute = $value; |
| 544 | + } |
| 545 | + }; |
| 546 | + |
| 547 | + $this->assertSame('scalar', $normalizer->denormalize('scalar', XmlScalarDummy::class, 'xml')->value); |
| 548 | + } |
519 | 549 | }
|
520 | 550 |
|
521 | 551 | class AbstractObjectNormalizerDummy extends AbstractObjectNormalizer
|
@@ -643,6 +673,12 @@ class DummyChild
|
643 | 673 | public $bar;
|
644 | 674 | }
|
645 | 675 |
|
| 676 | +class XmlScalarDummy |
| 677 | +{ |
| 678 | + /** @SerializedName("#") */ |
| 679 | + public string $value; |
| 680 | +} |
| 681 | + |
646 | 682 | class SerializerCollectionDummy implements SerializerInterface, DenormalizerInterface
|
647 | 683 | {
|
648 | 684 | private $normalizers;
|
|
0 commit comments