API Platform: Use custom serialised name
19 May 2023 (Updated 19 May 2023)
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
.
Tagged:
API Platform
Thanks for your comment 🙏. Once it's approved, it will appear here.
Leave a comment