-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Symfony Serializer is omitting attributes when using groups #54967
Comments
Can you create a small example application that allows to reproduce your issue? |
A small example can be found here: |
@th-lange Maybe I misunderstood your issue, but the reason you're getting the "incorrect" response is that you're using the diff --git a/src/Controller/FirstController.php b/src/Controller/FirstController.php
index 907cf11..a80c402 100644
--- a/src/Controller/FirstController.php
+++ b/src/Controller/FirstController.php
@@ -45,14 +45,14 @@ final class FirstController extends AbstractController
->setText('Some Text');
$noGroup = $this->normalizer->normalize($example, null, []);
- $example = $this->normalizer->normalize($example, null, [AbstractNormalizer::GROUPS => ['one']]);
+ $example1 = $this->normalizer->normalize($example, null, [AbstractNormalizer::GROUPS => ['one']]);
$example2 = $this->normalizer->normalize($example, null, [AbstractNormalizer::GROUPS => ['two']]);
$example3 = $this->normalizer->normalize($example, null, [AbstractNormalizer::GROUPS => ['id']]);
return new JsonResponse(
[
'noGroup' => $noGroup,
- 'example' => $example,
+ 'example' => $example1,
'example2' => $example2,
'id' => $example3,
] |
good catch @HypeMC, closing as explained then |
Symfony version(s) affected
7.0.7
Description
The symfony serializer behaves strangely. It serializes some grouped values depending on the order, they are serialized.
I use the example symfony project, where I created a controller:
File:
Controller/FirstController.php
and a simple Entity:
Entity/Example.php
When the route "test" is called, the normalizer will give (what seems to me to be) an incorrect response:
This is confusing - because it seems like, the other groups are not considered, when serializing and everything is a "group one" case. If I change the order things are serialized (in the
FirstController
from (one, two, id) to (id, two, one) ), the normalizer gives a correct response:Is this a bug or am I missing something?
How to reproduce
symfony new playground --version="7.0.*" --webapp
symfony composer require symfony/serializer
symfony composer install
symfony server:start
To verify inconsistent behavior, just shuffle the lines:
Possible Solution
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: