Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Serializer] AdddefaultType toDiscriminatorMap#59828

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

alanpoulain
Copy link
Contributor

@alanpoulainalanpoulain commentedFeb 21, 2025
edited
Loading

QA
Branch?7.3
Bug fix?no
New feature?yes
Deprecations?no
IssuesN/A
LicenseMIT

I thought it would be nice to have a default type value for the discriminator map of the serializer.

For instance with this configuration:

#[DiscriminatorMap(    typeProperty:'type',    mapping: ['article' => Article::class,'video' => Video::class,    ],    defaultType:'article')]abstractclass Element{publicstring$product;}finalclass Articleextends Element{publicstring$title;}finalclass Videoextends Element{publicint$duration;}

It would deserialize to anArticle with this data:

{"product":"desk","title":"PHP devs love Symfony"}

And to aVideo with this:

{"product":"desk","duration":8765,"type":"video"}

mttsch reacted with rocket emoji
@alanpoulainalanpoulainforce-pushed thediscriminator-map-default-value branch from83f1ca5 to828656fCompareFebruary 26, 2025 08:38
@alanpoulainalanpoulainforce-pushed thediscriminator-map-default-value branch from828656f toc03064aCompareFebruary 26, 2025 13:59
@alanpoulainalanpoulain changed the title[Serializer] AdddefaultValue toDiscriminatorMap[Serializer] AdddefaultType toDiscriminatorMapFeb 26, 2025
@alanpoulain
Copy link
ContributorAuthor

Thanks for the review@mtarld!

Copy link
Contributor

@mtarldmtarld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

With minor comments 🙂

@alanpoulainalanpoulainforce-pushed thediscriminator-map-default-value branch fromc03064a to9d089bdCompareFebruary 26, 2025 16:01
@fabpot
Copy link
Member

Thank you@alanpoulain.

@fabpotfabpot merged commitcb93a4f intosymfony:7.3Mar 1, 2025
9 of 11 checks passed
@fabpotfabpot mentioned this pull requestMay 2, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@MrYamousMrYamousMrYamous left review comments

@fabpotfabpotfabpot approved these changes

@mtarldmtarldmtarld approved these changes

@dunglasdunglasAwaiting requested review from dunglasdunglas is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
7.3
Development

Successfully merging this pull request may close these issues.

5 participants
@alanpoulain@fabpot@mtarld@MrYamous@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp