Open gremo opened 2 years ago
I want to use an handler only for deserialization. Upon serialization, the default handler should be used.
If I try to define a custom handler, registering it like this way:
app.serializer.relation_deserialization_handler: class: App\Serializer\RelationsHandler arguments: ['@doctrine.orm.entity_manager'] tags: - { name: jms_serializer.handler, type: Relation, direction: deserialization, format: json, method: deserialize }
<?php declare(strict_types=1); namespace App\Serializer; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadata; use JMS\Serializer\Context; use JMS\Serializer\Visitor\DeserializationVisitorInterface; class RelationsHandler { private $manager; public function __construct(EntityManagerInterface $manager) { $this->manager = $manager; } public function deserialize( DeserializationVisitorInterface $visitor, $relation, array $type, Context $context ) { $className = isset($type['params'][0]['name']) ? $type['params'][0]['name'] : null; } }
Class Relation does not exist in jms\metadata\src\MetadataFactory.php line 175.
I'm using it on a regular PHP property:
<?php declare(strict_types=1); namespace App\Entity; use Doctrine\ORM\Mapping as ORM; use JMS\Serializer\Annotation as Serializer; /** * @ORM\Entity() * @ORM\Table("customer") */ class Customer { /** * @ORM\ManyToOne(targetEntity="Agent") * @ORM\JoinColumn() * * @Serializer\Type("Relation<App\Entity\Agent>") * @Serializer\Groups({"customers:get_all", "customers:get_one", "customers:create"}) */ public ?Agent $agent = null; }
I want to use an handler only for deserialization. Upon serialization, the default handler should be used.
If I try to define a custom handler, registering it like this way:
I'm using it on a regular PHP property: