Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
Closed as not planned
Description
Symfony version(s) affected
7.1.5
Description
I probably problem with Ignore attribute and DiscriminatorMap at symfony 7.1.5
Example case:
<?phpdeclare(strict_types=1);namespace App\Test;use Symfony\Component\Serializer\Attribute\DiscriminatorMap;use Symfony\Component\Serializer\Attribute\Ignore;#[DiscriminatorMap( typeProperty: 'type', mapping: [ 'base_payload' => BasePayload::class, 'new_payload' => ExamplePayload::class, ],)]readonly class BasePayload{ public function __construct( protected string $a, ) { } public function getA(): string { return $this->a; } #[Ignore] public function isAString(): bool { return is_string($this->a); }}<?phpdeclare(strict_types=1);namespace App\Test;final readonly class ExamplePayload extends BasePayload{ public function __construct( string $a, protected string $b, ) { parent::__construct($a); } public function getB(): string { return $this->b; }}Runs this:
$serialized = $this->serializer->serialize($new BasePayload('string'), 'json');
But then i drop Ignore attribute - it passes (but with unnecessary key "aString") !!
{"type":"base_payload","a":"string","aString":true}
How to reproduce
<?phpdeclare(strict_types=1);namespace App\Test;use Symfony\Component\Serializer\Attribute\DiscriminatorMap;use Symfony\Component\Serializer\Attribute\Ignore;#[DiscriminatorMap( typeProperty: 'type', mapping: [ 'base_payload' => BasePayload::class, 'new_payload' => ExamplePayload::class, ],)]readonly class BasePayload{ public function __construct( protected string $a, ) { } public function getA(): string { return $this->a; } #[Ignore] public function isAString(): bool { return is_string($this->a); }}<?phpdeclare(strict_types=1);namespace App\Test;final readonly class ExamplePayload extends BasePayload{ public function __construct( string $a, protected string $b, ) { parent::__construct($a); } public function getB(): string { return $this->b; }}$serialized = $this->serializer->serialize($new BasePayload('string'), 'json');
Possible Solution
I tried to apply changes ofPR but it didn't help
Additional Context
No response
