【发布时间】:2020-12-08 05:18:12
【问题描述】:
我有一个具有一些 OneToOne 关系的实体:
/**
* @OA\Property(type="integer")
* @Serializer\Groups({"list", "detail"})
* @Serializer\Type("File::class")
* @ORM\OneToOne(targetEntity="File")
*/
private ?File $cv = null;
这里是文件实体:
/**
* @OA\Schema()
* @ORM\Entity(repositoryClass=FileRepository::class)
*/
class File
{
/**
* @OA\Property(type="integer")
* @Serializer\Groups({"list", "detail"})
* @Serializer\Type("integer")
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @OA\Property(type="string")
* @Serializer\Groups({"list", "detail"})
* @Serializer\Type("string")
* @ORM\Column(type="string", length=255, nullable=false)
*/
private $filename;
/**
* @OA\Property(type="string")
* @Serializer\Groups({"list", "detail"})
* @Serializer\Type("string")
* @ORM\Column(type="guid", nullable=false)
*/
private $uuid;
/**
* @OA\Property(type="string")
* @Serializer\Groups({"list", "detail"})
* @Serializer\Type("string")
* @ORM\Column(type="string", length=255, nullable=false)
*/
private $contentType;
/**
* @OA\Property(type="string", format="date-time")
* @Serializer\Groups({"list", "detail"})
* @Serializer\Type("string")
* @ORM\Column(type="date", length=255, nullable=false)
*/
private $creationDate;
当我尝试使用 JMS 序列化我的第一个实体时,使用 OneToOne 关系:
$data = $this->serializer->serialize($candidate, 'json', SerializationContext::create()->setGroups(array('detail'))->setSerializeNull(true));
总是报错:类文件不存在
显然,我的@Type 注释是错误的,但为什么呢?我该怎么办。
【问题讨论】:
标签: symfony jmsserializerbundle