-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
[Serializer] Allow to add groups to SerializedName annotation/attribute #46432
base: 7.2
Are you sure you want to change the base?
[Serializer] Allow to add groups to SerializedName annotation/attribute #46432
Conversation
src/Symfony/Component/Serializer/Mapping/Loader/YamlFileLoader.php
Outdated
Show resolved
Hide resolved
Hey! I think @mtarld has recently worked with this code. Maybe they can help review this? Cheers! Carsonbot |
src/Symfony/Component/Serializer/NameConverter/MetadataAwareNameConverter.php
Outdated
Show resolved
Hide resolved
@mtarld I can't "Re request review" but changes are done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost good!
src/Symfony/Component/Serializer/Mapping/AttributeMetadataInterface.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Serializer/Mapping/Loader/YamlFileLoader.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Serializer/Mapping/Loader/XmlFileLoader.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Serializer/Tests/Mapping/Loader/AnnotationLoaderTest.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Serializer/Tests/Mapping/Loader/YamlFileLoaderTest.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM then! 🙂
d01bf55
to
83941cd
Compare
(Rebased on current 6.2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. Here are some comments to help move forward.
src/Symfony/Component/Serializer/Mapping/Loader/YamlFileLoader.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Serializer/Mapping/Loader/YamlFileLoader.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Serializer/Mapping/AttributeMetadataInterface.php
Outdated
Show resolved
Hide resolved
afb3e7a
to
035b0dd
Compare
@nicolas-grekas I added layer and trigger deprecation (like urlMatcher) However, deprecation seems trigger even if methods are not called
public function testInterface()
{
$attributeMetadata = new AttributeMetadata('name');
$this->assertInstanceOf(AttributeMetadataInterface::class, $attributeMetadata);
} |
Can you try documenting the param explicitly the same way as the interface? It may be enough to avoid the notice. |
Indeed, It's enough, thank you @chalasr |
Friendly ping for re-review @nicolas-grekas |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are some more BC notes. Please rebase also.
...ymfony/Bundle/FrameworkBundle/Tests/Functional/Bundle/ModernBundle/config/serialization.yaml
Outdated
Show resolved
Hide resolved
*/ | ||
public $serializedName; | ||
public $serializedName = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For maximum BC, I think we should keep this as a string when possible, and use arrays only when actually required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nicolas-grekas , Tu be sure, somthing like this ?
/**
* string|array<string, string|null>
*/
public $serializedName;
And deal with string and array in every methods, is it right ?
* | ||
* @param string[] $groups | ||
*/ | ||
public function getSerializedName(/* array $groups = [] */): ?string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why pass an array here? Shouldn't we accept string|null instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used by MetadataAwareNameConverter
https://github.com/symfony/symfony/pull/46432/files#diff-87ffe277c0213fca753a8e0b26cc8f4436e255b9776e5e08852c403df247c5b9R121
Serializer group context can be multiple. So returned SerializerName
is the first matching group list.
Should be done in MetadataAwareNameConverter
?
Hello @alamirault, this is a great feature I was waiting for it for so long, do you you need help on this PR to resolve the latest feedbacks ? thanks |
922aabe
to
03d905e
Compare
Is this PR will be included in 6.2.X? or in 6.3? |
thank you for the contribution ! |
Will this one still be released? |
Any plans to make it released? |
We just ran into this need. We need to deserialize from xml we don't control, and serialize to json. Doing this any other way would be extremely complex as we're already dealing with a few hundred objects. Duplicating all of that to control it differently is not an option. |
Would it be hard to add to |
I really appreciate the works that people have put into this feature. Would be valuable to see this being merged in the near future because this gives us more control (and less unwanted/unexpected behaviour) within de Serializer. |
Somebody would need to pick up the work and rebase the changes onto 7.2. |
Sorry guys, I completely missed this PR and discussion and created my own PR (#58236) 🤦♂️. |
This PR allow to configure serialization groups for annotation
SerializedName
. Inspired by PR #37903.Before we can only define
#[SerializedName('nameOne')]
. Now, name can be different depending of groupAttributes
Annotations
YAML
XML