|
21 | 21 | use Symfony\Component\Serializer\Encoder\DecoderInterface; |
22 | 22 | use Symfony\Component\Serializer\Encoder\EncoderInterface; |
23 | 23 | use Symfony\Component\Serializer\Encoder\JsonEncoder; |
| 24 | +use Symfony\Component\Serializer\Encoder\XmlEncoder; |
24 | 25 | use Symfony\Component\Serializer\Exception\ExtraAttributesException; |
25 | 26 | use Symfony\Component\Serializer\Exception\InvalidArgumentException; |
26 | 27 | use Symfony\Component\Serializer\Exception\LogicException; |
|
61 | 62 | use Symfony\Component\Serializer\Tests\Fixtures\DummyMessageNumberOne; |
62 | 63 | use Symfony\Component\Serializer\Tests\Fixtures\DummyMessageNumberThree; |
63 | 64 | use Symfony\Component\Serializer\Tests\Fixtures\DummyMessageNumberTwo; |
| 65 | +use Symfony\Component\Serializer\Tests\Fixtures\DummyNullableInt; |
64 | 66 | use Symfony\Component\Serializer\Tests\Fixtures\DummyObjectWithEnumConstructor; |
65 | 67 | use Symfony\Component\Serializer\Tests\Fixtures\DummyObjectWithEnumProperty; |
66 | 68 | use Symfony\Component\Serializer\Tests\Fixtures\DummyWithObjectOrNull; |
@@ -740,6 +742,19 @@ public function testDeserializeWrappedScalar() |
740 | 742 | $this->assertSame(42, $serializer->deserialize('{"wrapper": 42}', 'int', 'json', [UnwrappingDenormalizer::UNWRAP_PATH => '[wrapper]'])); |
741 | 743 | } |
742 | 744 |
|
| 745 | + /** |
| 746 | + * @requires PHP 8 |
| 747 | + */ |
| 748 | + public function testDeserializeNullableIntInXml() |
| 749 | + { |
| 750 | + $extractor = new PropertyInfoExtractor([], [new ReflectionExtractor()]); |
| 751 | + $serializer = new Serializer([new ObjectNormalizer(null, null, null, $extractor)], ['xml' => new XmlEncoder()]); |
| 752 | + |
| 753 | + $obj = $serializer->deserialize('<?xml version="1.0" encoding="UTF-8"?><DummyNullableInt><value/></DummyNullableInt>', DummyNullableInt::class, 'xml'); |
| 754 | + $this->assertInstanceOf(DummyNullableInt::class, $obj); |
| 755 | + $this->assertNull($obj->value); |
| 756 | + } |
| 757 | + |
743 | 758 | public function testUnionTypeDeserializable() |
744 | 759 | { |
745 | 760 | $classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader())); |
|
0 commit comments