use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\SerializedName;
// All the usual annotations on user....
class User {
#[Groups(['user:read:item'])]
#[SerializedName('hasCreatedArticle')]
public function hasCreatedArticle(): bool
{
return $this->getArticles()->count() > 0;
}
Now, you’ll get a hasCreatedArticle
field name instead of the default createdArticle
.