symfony
symfony copied to clipboard
[Serializer] Add support for union collection value types in `ArrayDenormalizer`
Q | A |
---|---|
Branch? | 7.2 |
Bug fix? | no |
New feature? | yes |
Deprecations? | no |
License | MIT |
Currently only the following array types combination is supported: array<MyObject>|array<Another>
. This results in arrays with only 1 type of objects.
This PR aims to add support for arrays where values can be either of those, like union types: array<MyObject|Another>
.
I've currently tested is successfully against the following types:
-
DateTimeInterface[]
-
array<array<DateTimeInterface|DateInterval|string>>
-
array<DateTimeInterface>|array<DateInterval>
-
array<DateTimeInterface|DateInterval>
-
array<DateTimeInterface|null>
See also https://github.com/Jeroeny/reproduce/blob/mixedarray/src/Test.php
Anyone with more background on Serializer would be willing to review this PR? (note that it should target 7.1 for now, maybe 7.2 if we can't make it since we're in feature freeze now). /cc @mtarld maybe? Anyone else?
As https://github.com/symfony/symfony/pull/53160 has been merged, the validateAndDenormalize
method is now using Type
of TypeInfo component, which can make this patch easier.
So, this PR has to be rebased and updated accordingly.
Rebased onto 7.1 and description targeting 7.2.
The new validateAndDenormalizeLegacy
vs validateAndDenormalize` are a bit complex, so not sure yet how to apply the changes to the method using the new types.