我想运行JMSSerializer。我简单的代码主义注释加载失败
use JMS\Serializer\Annotation\Type;
class Comment
{
private $msg;
public function __construct($msg)
{
$this->msg = $msg;
}
}
class Person
{
/**
* @Type("array<Comment>")
*/
private $commentList;
public function addComment(Comment $comment)
{
$this->commentList[] = $comment;
}
}
$type = new Type;
$serializer = JMS\Serializer\SerializerBuilder::create()->build();
$data = new Person();
$data->addComment(new Comment('hey'));
var_dump($serializer->serialize($data, 'json'));
失败
PHP Fatal error: Uncaught exception 'Doctrine\Common\Annotations\AnnotationException' with message '[Semantical Error] The annotation "@JMS\Serializer\Annotation\Type" in property Person::$commentList does not exist, or could not be auto-loaded.' in xxx.php:52
OK,但如果我添加行
$type = new Type;
手动触发自动加载磁带机,它的工作原理:
string(32) "{"comment_list":[{"msg":"hey"}]}"
正如我请参阅AnnotationRegistry不使用自动加载器,它三es使用一些自己的自动加载器。它看起来很丑陋,我需要做些什么来修复它?
可能重复[JMSSerializer独立 - 注释不存在,或不能自动加载](http://stackoverflow.com/questions/14629137/jmsserializer-stand-alone-annotation-does-not-exist-或者,不能待自动加载) –