条令序列化程序:使用组的问题



我正在为我的实体使用symfony序列化程序,除非每当我尝试在实体属性上使用组时,我都会收到以下错误:

[Semantical Error] The annotation "@SymfonyComponentSerializerAnnotationGroups" in property 
AppEntitiesUser::$id was never imported. Did you maybe forget to add a "use" statement for this 
annotation?

这是我的实体:

namespace AppEntities;
use DoctrineORMMapping AS ORM;
use SymfonyComponentSerializerAnnotationGroups;
/**
* @ORMEntity
*/
class User
{
/**
* @ORMId
* @Groups("user_show")
* @ORMColumn(type="string")
*/
protected $id;
/**
* @ORMColumn(type="string")
*/
protected $password;
}

我的AppServiceProvider(我使用的是Laravel(中有这个代码

public function boot()
{
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
$encoders = [new JsonEncoder()];
$normalizers = [new ObjectNormalizer($classMetadataFactory)];
$this->app->bind(SerializerInterface::class, function () use ($normalizers, $encoders) {
return new Serializer($normalizers, $encoders);
});
}

通过为laravel学说注册符号注释来解决问题更多信息点击这里

相关内容

  • 没有找到相关文章

最新更新