-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] Attribute SerializedName
ignored when property name is the same as the related (get|has|can) method
#54109
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
Comments
Hello, In a regular use case, you'll probably never call your properties with the same as their accessors (e.g. But after digging around your problem, I can reproduce it. I'll try to work on it, but let's wait for somebody more experienced to see if it's not the expected behavior. Just for your information, the command is missing in your project, but I guess it looks like this ? <?php
namespace App\Command;
use App\Entity\ListView;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Serializer\SerializerInterface;
#[AsCommand(name: 'app:test:test')]
class TestCommand extends Command
{
public function __construct(
private readonly SerializerInterface $serializer
) {
parent::__construct();
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$listView = new ListView(true, false, true, false);
$output->writeln($this->serializer->serialize($listView, 'json'));
return Command::SUCCESS;
}
} |
I indeed forgot the command and apologize for this but you got it. I'll commit it anyway. As for the "regular use case", I do agree with you but this would be considering people are perfect beings or at least fluent enough in english to avoid literal translations. |
Hello, I've open a PR to fix your issue. See #54148 |
… same name as their accessor (NeilPeyssard) This PR was merged into the 5.4 branch. Discussion ---------- [Serializer] Fix object normalizer when properties has the same name as their accessor | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #54109 | License | MIT Hello, This PR fix a bug in object normalization when properties has the same name as their accessor. The current behavior mess up class metadata between properties and methods so the keys in the normalized format does not match the object properties, and metadata are not correctly applied (`SerializedName` in our exemple). This bug also affects versions 6.4 and 7+, but I'm not sure if we can merge this PR in these branches without refactoring. Let me know if another PR should be open for version 6.4 and 7. Commits ------- 8575199 [Serializer] Fix object normalizer when properties has the same name as their accessor
Fix reverted in #54635, should be resubmitted against the development branch. |
Hey, thanks for your report! |
Could I get a reply or should I close this? |
Hey, I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen! |
Symfony version(s) affected
7.0.*
Description
Symfony serializer ignores the attribute
SerializedName
for properties sharing the same name as the related method shall it start bycan
,has
orget
.How to reproduce
Clone this repository created specifically and use the following command :
This will output the string of a json serialized
App\Entity\ListView
object.Expected output :
Current output :
Possible Solution
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: