Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
SerializedName based on Groups#37903
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
SerializedName based on Groups#37903
Uh oh!
There was an error while loading.Please reload this page.
Conversation
dunglas commentedAug 24, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
What do you think about using the following signature: /** * @SerializedName("bar") <-- Applied only when no groups are provided * @SerializedName("baz", groups={"a", "b"}) <-- Applied if group is a or b * @SerializedName("bat", groups="c") <-- Applied if group is c */$foo; If find this easier to read and write. |
Uh oh!
There was an error while loading.Please reload this page.
The doctrine annotation reader is capable of handling the same annotation multiple time on a property so this shouldn't be a problem. |
1d61e0f
to9620fe8
Comparecc@dunglas or other people for review |
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Serializer/Mapping/AttributeMetadataInterface.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Serializer/Mapping/AttributeMetadataInterface.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
04c47ef
to3c24e9f
CompareUh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Serializer/Mapping/Loader/YamlFileLoader.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Serializer/Mapping/Loader/YamlFileLoader.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Serializer/NameConverter/MetadataAwareNameConverter.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
@jsamouh Can you squash your commits? |
56b6f1c
tod77f3d0
Compared77f3d0
to14beaec
Compare@@ -111,15 +109,51 @@ public function getMaxDepth() | |||
*/ | |||
public function setSerializedName(string $serializedName = null) | |||
{ | |||
$this->serializedName = $serializedName; | |||
$this->addSerializedName($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.
you cannot pass null here.
* Adds the serialization name for this attribute. | ||
*/ | ||
public function addSerializedName(string $serializedName, array $groups = []); | ||
/** | ||
* Gets the serialization name for this attribute. | ||
*/ | ||
public function getSerializedName(): ?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.
id remove/deprecate this one
foreach ($this->serializedNames as $serializedName => $groupsForSerializedName) { | ||
if (!$groupsForSerializedName) { | ||
$defaultSerializedName = $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.
i dont think you can make this assumption :/ any name without groups could be considered default
i think we should also validate that there can only be 1 default name (no groups) as well as validating no overlap, e.g. 2 names with the same groups. |
I understand your point... I m shared between let the behavior like this and be strict on it. Need a second thought on that cc@dunglas@fabpot Thanks for your feedback |
I tend to agree with@ro0NL |
serialized_name: 'full_name' | ||
serialized_names: 'full_name' |
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.
seems to break user configs, thus BC
IMHO we can keep supporting 2 formats:
ser_name:'some'ser_names:some:~other:[grp1, grp2]
} | ||
$attributeMetadata->addSerializedName($data['serialized_names']); | ||
} elseif (\is_array($data['serialized_names'])) { | ||
if (empty($data['serialized_names'])) { |
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.
if (!$data['serialized_names']) {
throw new MappingException(sprintf('The "serialized_names" value must be a non-empty array of serialized name/groups in "%s" for the attribute "%s" of the class "%s".', $this->file, $attribute, $classMetadata->getName())); | ||
} | ||
foreach ($data['serialized_names'] as $serializedName => $groups) { | ||
if (!\is_string($serializedName) || empty($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.
|| '' === trim($serializedName)
/** | ||
* Adds the serialization name for this attribute. | ||
*/ | ||
public function addSerializedName(string $serializedName, array $groups = []); |
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.
IMHO should this one should besetSerializedNames
(no need for an adder) - which simplifies resetting
setSerializedName(null) previous, vs setSerializedNames([]) now
We've just moved away from |
hafkenscheid commentedJun 23, 2021
Is there already a new PR for this? |
I don't think so. |
will dot it next week |
This would still be immensely useful for refactoring/versioning things. |
Uh oh!
There was an error while loading.Please reload this page.
New Feature: Serialized Name based on Groups