Php JMS序列化程序注释
我使用的是Doctrine2和,但是序列化程序抛出了一个奇怪的错误: AnnotationException:[语义错误]类原则\ORM\Mapping\PrePersist未使用@Annotation进行注释。您确定此类可以用作批注吗?如果是这样,那么您需要将@Annotation添加到doctor\ORM\Mapping\PrePersist的类doc注释中。如果确实没有注释,则需要将@IgnoreAnnotationORM\PrePersist添加到方法User\User::PrePersist的类文档注释中 当我尝试序列化实体对象时会发生这种情况。这些是实体类的相关位:Php JMS序列化程序注释,php,symfony,doctrine-orm,jmsserializerbundle,Php,Symfony,Doctrine Orm,Jmsserializerbundle,我使用的是Doctrine2和,但是序列化程序抛出了一个奇怪的错误: AnnotationException:[语义错误]类原则\ORM\Mapping\PrePersist未使用@Annotation进行注释。您确定此类可以用作批注吗?如果是这样,那么您需要将@Annotation添加到doctor\ORM\Mapping\PrePersist的类doc注释中。如果确实没有注释,则需要将@IgnoreAnnotationORM\PrePersist添加到方法User\User::PrePers
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as JMS;
/**
* @ORM\Entity
* @ORM\Table(name="products", indexes={
* @ORM\Index(columns={"price"}),
* })
* @ORM\HasLifecycleCallbacks
*/
class Product
{
// ...
/**
* @ORM\PrePersist
*/
public function prePersist()
{
$this->createdAt = new \DateTime;
$this->updatedAt = $this->createdAt;
}
// ...
}
我打开了Doctrine\ORM\Mapping\PrePersist,它用@Annotation注释。因此,这个bug似乎是站在JMS这一边的,而不是教义2
这是什么原因造成的
注意:在这种情况下,正确的标记应该是“jmsserializer”,而不是“JMSSerializarbundle”。如果合适,请有人创建它和/或删除此注释。您混淆了两件事:教义和JMSSerializer 您应该确切地告诉JMSSerializer您想要序列化的内容。因此,请尝试排除所有内容,并对希望序列化的所有内容进行注释。 就像这样:
use Doctrine\ORM\Mapping as ORM;
use JMS\Serializer\Annotation as JMS;
/**
* @ORM\Entity
* @ORM\Table(name="products", indexes={
* @ORM\Index(columns={"price"}),
* })
* @ORM\HasLifecycleCallbacks
* @JMS\ExclusionPolicy("all")
*/
class Product
{
/**
* @var string
*
* @ORM\Column(name="serializableProperty1", type="guid")
*
* @JMS\Expose
*/
private $serializableProperty1;
/**
* @ORM\PrePersist
*/
public function prePersist()
{
$this->createdAt = new \DateTime;
$this->updatedAt = $this->createdAt;
}
// ...
}