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] Denormalize support forstdClass#52850

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

Open
nightio wants to merge1 commit intosymfony:6.4
base:6.4
Choose a base branch
Loading
fromnightio:denormalize-support-for-stdClass

Conversation

nightio
Copy link

@nightionightio commentedDec 1, 2023
edited
Loading

QA
Branch?6.4
Bug fix?no
New feature?no
Deprecations?no
Issues-
LicenseMIT

Add support for denormalizing stdClass objects in Symfony serializer

@carsonbotcarsonbot added this to the6.4 milestoneDec 1, 2023
@nightionightioforce-pushed thedenormalize-support-for-stdClass branch from43d71df to0479a92CompareDecember 5, 2023 10:50
@nightio
Copy link
Author

@dunglas could you make a code review and eventually merge the commit?

@chalasrchalasr modified the milestones:6.4,7.1Jan 29, 2024
@nightionightioforce-pushed thedenormalize-support-for-stdClass branch from0479a92 to0238782CompareMarch 14, 2024 11:32
@nightionightioforce-pushed thedenormalize-support-for-stdClass branch from0238782 to20a49a9CompareMarch 14, 2024 12:53
@nightionightio changed the titleDenormalize support for std class[Serializer] Denormalize support for std classMar 14, 2024
@nightio
Copy link
Author

@nicolas-grekas Could you please make a review?

@stof
Copy link
Member

Instead of hacking that in the ObjectNormalizer, I think this should rather be a new Normalizer

@nightio
Copy link
Author

@stof Good point. However, currently the normalizing process of stdClass is part of the same class -https://github.com/symfony/symfony/pull/52850/files#diff-397b4689ce56cc95e54911f6d78639bb3258a9ee9b36bfa06ec719e9635e6b1dR67

@nightio
Copy link
Author

@stof I thought about it and think it should be part of the ObjectNormalizer.

  1. it is an object and, at the same time, the simplest object.
  2. Some bundles already use ObjectNormalizer to normalize properties of type stdClass, but it cannot be denormalized. e.g.https://github.com/dunglas/doctrine-json-odm -https://github.com/dunglas/doctrine-json-odm/blob/main/src/Bundle/Resources/config/services.xml

@stof@dunglas Could you please make a review and eventually merge it?

@stof
Copy link
Member

stof commentedApr 3, 2024

  1. it is an object and, at the same time, the simplest object.

if we go that way,all core normalizers would be removed by bundling them into ObjectNormalizer, because BackedEnum or DateTime are also objects.

ObjectNormalizer is not about being the implementation to use for all objects. It is thegeneric implementation used for objects that don't have another normalizer registered with a higher priority to take over the normalization with specific logic.

2. Some bundles already use ObjectNormalizer to normalize properties of type stdClass, but it cannot be denormalized.

The JSON ODM does not use the ObjectNormalizer directly. It uses a Serializer with multiple normalizers registered in it. This means that they could totally register the new normalizer once it is available. They already did exactly that for the BackedEnumNormalizer and the UidNormalizer btw.

derrabus and mtarld reacted with thumbs up emoji

@derrabus
Copy link
Member

I'm with@stof here. Adding special behavior for a specific class usually means we're adding a new normalizer.

@mtarld
Copy link
Contributor

Agreed as well. TheObjectNormalizer is kind of big enough...

Plus, astdClass dedicated normalizer could be way faster than theObjectNormalizer one.
Therefore, the developers willing to normalizestdClass only will be able to use this instead of theObjectNormalizer one and have a performance boost, which is great!

@jg-development
Copy link

We have this problem too:
#54613
Is somebody already working on this normalizer? Otherwise if I have some time, I will step in.

@mtarld
Copy link
Contributor

AKAIK, there is no ongoing work on that normalizer, so feel free to step in 🙂

@jg-development
Copy link

Questions regarding "new normalizer". What about a class, that is a mixture of stdclass and object?

<?phpdeclare(strict_types =1);usestdClass;class Contactextends stdClass{publicstring$email ='';}

I am not sure if a new normalizer is the best solution here.
I am not an expert in the normalizer logic, but the "StdClassNormalizer" cannot work with logic of the "ObjectNormalizer" + "AbstractObjectNormalizer".
"ObjectNormalizer" is a final class, so a new "StdClassNormalizer" has a lot of duplicate code from the "ObjectNormalizer".

But I will kick in and give feedback

jg-development pushed a commit to jg-development/symfony that referenced this pull requestNov 5, 2024
@jg-development
Copy link

Hi..
I added a pull (7.2) for adding the support of stdclasses. I added this feature directly into the objectnormalizer.

The problem with an extra stdclass normalizer is the shared logic of stdclass objects and objects that extends stdclasses.
In the end, we would have a lot of duplicate code in the StdclassNormalizer + ObjectNormalizer. And putting everything in the AbstractObjectNormalizer would have impact on the other normalizers (GetSetMethodNormalizer, PropertyNormalizer).

It should be possible to extract the stdclass logic into a StdclassNormalizer and extend the ObjectNormalizer.
But I am not an expert of this normalizers, so if somebody with more inside .... feel free to change the pull.

Imho the ObjectNormalizer needs an overhaul, but this is an issue for later and not for now. Maybe, than it is possible to seperate the normalizers.

@OskarStarkOskarStark changed the title[Serializer] Denormalize support for std class[Serializer] Denormalize support forstdClassNov 5, 2024
jg-development pushed a commit to jg-development/symfony that referenced this pull requestNov 5, 2024
jg-development pushed a commit to jg-development/symfony that referenced this pull requestNov 5, 2024
jg-development pushed a commit to jg-development/symfony that referenced this pull requestNov 5, 2024
@jg-development
Copy link

@dunglas
the coding style hates me, but the style problems are not within my code, but within existing code.
maybe execute coding style in another commit/issue.

@mtarld
Copy link
Contributor

What about acting directly onPropertyAccessor instead?

The actual behavior in PropertyAccessor is checking the following:$object instanceof \stdClass && property_exists($object, $property).
And it will work for dynamic properties if we only have checked$object instanceof \stdClass.

I'm still not sure why we need thatproperty_exists check. I've seen most of them have been introduced insymfony/property-access@2d75186, so maybe you can help us@alexandre-daubois?

@alexandre-daubois
Copy link
Member

The property_exists is used to check whether a property with a. exists in the object or not. It is an edge case, only possible when casting an array to an object with(object) (and maybe with ArrayObjects?). Ifproperty_exists returns false, then this means we are actually dealing with aproperty path, not an actual property of the object. Again, this truly is an edge-case 😄

@jg-development
Copy link

@mtarld@alexandre-daubois
Thx for th info.... I always asked myself: why on earth was that property_exists added? ;-)

@fabpotfabpot modified the milestones:7.2,7.3Nov 20, 2024
@fabpotfabpot modified the milestones:7.3,7.4May 26, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@dunglasdunglasAwaiting requested review from dunglasdunglas is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
7.4
Development

Successfully merging this pull request may close these issues.

10 participants
@nightio@stof@derrabus@mtarld@jg-development@alexandre-daubois@fabpot@xabbuh@chalasr@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp