Skip to content

[Serializer] Add support for union collection value types in ArrayDenormalizer #52018

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 7.3
Choose a base branch
from

Conversation

Jeroeny
Copy link
Contributor

@Jeroeny Jeroeny commented Oct 12, 2023

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

@Jeroeny Jeroeny requested a review from dunglas as a code owner October 12, 2023 13:17
@Jeroeny Jeroeny force-pushed the mixedarray branch 5 times, most recently from 3e542ae to cb066b3 Compare October 12, 2023 15:19
@nicolas-grekas nicolas-grekas added this to the 7.1 milestone Oct 27, 2023
@nicolas-grekas
Copy link
Member

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?

@mtarld
Copy link
Contributor

mtarld commented Apr 12, 2024

As #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.

@Jeroeny
Copy link
Contributor Author

Jeroeny commented May 6, 2024

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.

@xabbuh xabbuh modified the milestones: 7.1, 7.2 May 15, 2024
@fabpot fabpot modified the milestones: 7.2, 7.3 Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants