[英]Symfony 5.2 Error: The directory “var/cache/dev/jms_serializer” does not exist
[英]JMS Serializer / Symfony class does not exist
我有一個具有一些 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));
我總是收到錯誤:Class 文件不存在
顯然,這是我的@Type
注釋錯誤,但為什么呢? 我應該怎么辦。
嘗試改變這個:
@Serializer\Type("File::class")
對此(無引號):
@Serializer\Type(File::class)
我懷疑它可能正在尋找文字字符串"File::class"
,而不是解析 class 名稱。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.