@@ -1147,6 +1147,25 @@ public function testDenormalizeCollectionOfScalarTypesPropertyWithPhpDocExtracto
1147
1147
1148
1148
$ this ->assertEquals ($ expected , $ normalizer ->denormalize ($ data , ScalarCollectionDocBlockDummy::class));
1149
1149
}
1150
+
1151
+ public function testDenormalizeCollectionOfUnionTypesPropertyWithPhpDocExtractor ()
1152
+ {
1153
+ $ normalizer = new AbstractObjectNormalizerWithMetadataAndPhpDocExtractor ();
1154
+ $ data = [
1155
+ 'values1 ' => [
1156
+ 'foo ' => 'foo ' ,
1157
+ 'bar ' => 222 ,
1158
+ ],
1159
+ 'values2 ' => [
1160
+ 'baz ' => 'baz ' ,
1161
+ 'qux ' => 333 ,
1162
+ ],
1163
+ ];
1164
+ $ expected = new UnionCollectionDocBlockDummy ($ data ['values1 ' ]);
1165
+ $ expected ->values2 = $ data ['values2 ' ];
1166
+
1167
+ $ this ->assertEquals ($ expected , $ normalizer ->denormalize ($ data , UnionCollectionDocBlockDummy::class));
1168
+ }
1150
1169
}
1151
1170
1152
1171
class AbstractObjectNormalizerDummy extends AbstractObjectNormalizer
@@ -1577,6 +1596,22 @@ public function getValues(): ?array
1577
1596
}
1578
1597
}
1579
1598
1599
+ class UnionCollectionDocBlockDummy
1600
+ {
1601
+ /**
1602
+ * @param array<string, string|int> $values1
1603
+ */
1604
+ public function __construct (
1605
+ public array $ values1 ,
1606
+ ) {
1607
+ }
1608
+
1609
+ /**
1610
+ * @var array<string, string|int>
1611
+ */
1612
+ public array $ values2 ;
1613
+ }
1614
+
1580
1615
class AbstractObjectNormalizerWithMetadataAndPhpDocExtractor extends AbstractObjectNormalizer
1581
1616
{
1582
1617
public function __construct ()
@@ -1596,6 +1631,9 @@ protected function getAttributeValue(object $object, string $attribute, ?string
1596
1631
1597
1632
protected function setAttributeValue (object $ object , string $ attribute , mixed $ value , ?string $ format = null , array $ context = []): void
1598
1633
{
1634
+ if (property_exists ($ object , $ attribute )) {
1635
+ $ object ->$ attribute = $ value ;
1636
+ }
1599
1637
}
1600
1638
1601
1639
public function getSupportedTypes (?string $ format ): array
0 commit comments