1

Doctrine2 とJMS Serializerを使用していますが、シリアライザーが奇妙なエラーをスローしています:

AnnotationException: [Semantical Error] クラス "Doctrine\ORM\Mapping\PrePersist" に @Annotation の注釈が付けられていません。このクラスを注釈として使用できますか? その場合、"Doctrine\ORM\Mapping\PrePersist"のクラスドキュメント コメントに @Annotation を追加する必要があります。本当に注釈がない場合は、@IgnoreAnnotation("ORM\PrePersist") をメソッド User\User::prePersist()のクラスdoc コメントに追加する必要があります。

これは、エンティティ オブジェクトをシリアル化しようとすると発生します。これらは、エンティティ クラスの関連ビットです。

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付けられています。したがって、バグは Doctrine2 ではなく JMS 側にあるようです。

何が原因でしょうか?

注: この場合の正しいタグは、「jmsserializerbundle」ではなく「jmsserializer」です。必要に応じて誰かが作成するか、このメモを削除してください。

4

1 に答える 1