Add support for serializing identifiers in PersonJsonNormalizer and improve PersonIdentifier entity serialization.

- Extended `PersonJsonNormalizer` to include `identifiers` field normalization.
- Added `Serializer` annotations to `PersonIdentifier` and `PersonIdentifierDefinition` for enhanced serialization support.
- Updated `PersonIdentifier` and `PersonIdentifierDefinition` to define serialization groups and discriminator maps.
This commit is contained in:
2025-10-29 15:04:50 +01:00
parent e291c7abec
commit 8c2acbd166
4 changed files with 11 additions and 1 deletions

View File

@@ -15,6 +15,7 @@ use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\PersonIdentifier\Validator\UniqueIdentifierConstraint;
use Chill\PersonBundle\PersonIdentifier\Validator\ValidIdentifierConstraint;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation as Serializer;
#[ORM\Entity]
#[ORM\Table(name: 'chill_person_identifier')]
@@ -22,11 +23,13 @@ use Doctrine\ORM\Mapping as ORM;
#[ORM\UniqueConstraint(name: 'chill_person_identifier_unique_person_definition', columns: ['definition_id', 'person_id'])]
#[UniqueIdentifierConstraint]
#[ValidIdentifierConstraint]
#[Serializer\DiscriminatorMap('type', ['person_identifier' => PersonIdentifier::class])]
class PersonIdentifier
{
#[ORM\Id]
#[ORM\Column(name: 'id', type: \Doctrine\DBAL\Types\Types::INTEGER)]
#[ORM\GeneratedValue]
#[Serializer\Groups(['read'])]
private ?int $id = null;
#[ORM\ManyToOne(targetEntity: Person::class)]
@@ -34,6 +37,7 @@ class PersonIdentifier
private ?Person $person = null;
#[ORM\Column(name: 'value', type: \Doctrine\DBAL\Types\Types::JSON, nullable: false, options: ['default' => '[]', 'jsonb' => true])]
#[Serializer\Groups(['read'])]
private array $value = [];
#[ORM\Column(name: 'canonical', type: \Doctrine\DBAL\Types\Types::TEXT, nullable: false, options: ['default' => ''])]
@@ -42,6 +46,7 @@ class PersonIdentifier
public function __construct(
#[ORM\ManyToOne(targetEntity: PersonIdentifierDefinition::class)]
#[ORM\JoinColumn(name: 'definition_id', referencedColumnName: 'id', nullable: false, onDelete: 'RESTRICT')]
#[Serializer\Groups(['read'])]
private PersonIdentifierDefinition $definition,
) {}