Can';t将整个用户发送到API json响应,仅发送id和电子邮件

Can';t将整个用户发送到API json响应,仅发送id和电子邮件,json,api,symfony,Json,Api,Symfony,我试图将我的用户实体发送回前端,但只发送id和电子邮件,而不发送其他属性。 其他属性是使用@组,如id和电子邮件。正如你将看到的,我无法发送回复id和电子邮件。所以我不明白问题出在哪里。 我有使用Symfony\Component\Serializer\Annotation\Groups 我的实体用户: /** *@ORM\Table(name=“`user`”) *@ORM\Entity(repositoryClass=UserRepository::class) */ 类用户实现用户接口,\

我试图将我的用户实体发送回前端,但只发送id和电子邮件,而不发送其他属性。 其他属性是使用@组,如id和电子邮件。正如你将看到的,我无法发送回复id和电子邮件。所以我不明白问题出在哪里。 我有
使用Symfony\Component\Serializer\Annotation\Groups

我的实体用户:

/**
*@ORM\Table(name=“`user`”)
*@ORM\Entity(repositoryClass=UserRepository::class)
*/
类用户实现用户接口,\n可序列化
{
/**
*@ORM\Id()
*@ORM\GeneratedValue()
*@ORM\Column(type=“integer”)
*@Groups(“apiv0”)
*/
私人$id;
/**
*@ORM\Column(type=“json”)
*@Groups(“apiv0”)
*/
私有$roles=[];
/**
*@ORM\Column(type=“string”,length=180,unique=true)
*@Groups(“apiv0”)
*/
私人电子邮件;
/**
*@var string哈希密码
*@ORM\Column(type=“string”)
*@Groups(“apiv0”)
*/
私人$password;
/**
*@ORM\OneToMany(targetEntity=Bloodsugar::class,mappedBy=“user”)
*@Groups(“apiv0”)
*/
私人的$bloodugars;
/**
*@ORM\Column(type=“string”,长度=50)
*@Groups(“apiv0”)
*/
私人$lastname;
/**
*@ORM\Column(type=“string”,长度=50)
*@Groups(“apiv0”)
*/
私人$firstname;
/**
*@ORM\Column(type=“float”)
*@Groups(“apiv0”)
*/
私人$target_min;
/**
*@ORM\Column(type=“float”)
*@Groups(“apiv0”)
*/
私人$target_max;
/**
*@ORM\Column(type=“string”,length=50,nullable=true)
*@Groups(“apiv0”)
*/
私人$doctor_name;
/**
*@ORM\Column(type=“string”,长度=20)
*@Groups(“apiv0”)
*/
私人型;
/**
*@ORM\Column(type=“string”,length=50,nullable=true)
*@Groups(“apiv0”)
*/
私人$doctor_电子邮件;
/**
*@ORM\Column(type=“datetime”)
*@Groups(“apiv0”)
*/
在创建的私有$u;
/**
*@ORM\Column(type=“string”,长度=255)
*@Groups(“apiv0”)
*/
私有$username;
我的控制器:

$userCreated=$repository->find($user->getId());
转储($用户);
转储($userCreated);
$response=$this->json($userCreated,200,[],['groups'=>'apiv0']);
dd(答复);
返回$response
我的沮丧:


您应该在组定义中使用图形括号,因此请执行以下操作:

/**
 * @ORM\Column(type="string", length=180, unique=true)
 * @Groups({"apiv0"})
 */
private $email;
与此相反:

/**
 * @ORM\Column(type="string", length=180, unique=true)
 * @Groups("apiv0")
 */
private $email;

…有什么好的理由把密码放在API响应中吗?太好了,效果很好,非常感谢。我在我的前一个项目中使用了无{},它成功了。你能告诉我为什么不在这个项目中使用吗?