From 322180bde40dea2e92259932f02914eba614b52b Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 21 Aug 2016 12:48:31 +0200 Subject: [PATCH] Added tag property to json serialization of ShortUrl --- module/Core/src/Entity/ShortUrl.php | 2 +- module/Core/src/Entity/Tag.php | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/module/Core/src/Entity/ShortUrl.php b/module/Core/src/Entity/ShortUrl.php index c89324ad..cf1ed87e 100644 --- a/module/Core/src/Entity/ShortUrl.php +++ b/module/Core/src/Entity/ShortUrl.php @@ -178,7 +178,7 @@ class ShortUrl extends AbstractEntity implements \JsonSerializable 'originalUrl' => $this->originalUrl, 'dateCreated' => isset($this->dateCreated) ? $this->dateCreated->format(\DateTime::ISO8601) : null, 'visitsCount' => count($this->visits), - 'tags' => $this->tags, + 'tags' => $this->tags->toArray(), ]; } } diff --git a/module/Core/src/Entity/Tag.php b/module/Core/src/Entity/Tag.php index 7f10cfdf..47123ff9 100644 --- a/module/Core/src/Entity/Tag.php +++ b/module/Core/src/Entity/Tag.php @@ -12,7 +12,7 @@ use Shlinkio\Shlink\Common\Entity\AbstractEntity; * @ORM\Entity() * @ORM\Table(name="tags") */ -class Tag extends AbstractEntity +class Tag extends AbstractEntity implements \JsonSerializable { /** * @var string @@ -37,4 +37,16 @@ class Tag extends AbstractEntity $this->name = $name; return $this; } + + /** + * Specify data which should be serialized to JSON + * @link http://php.net/manual/en/jsonserializable.jsonserialize.php + * @return mixed data which can be serialized by json_encode, + * which is a value of any type other than a resource. + * @since 5.4.0 + */ + public function jsonSerialize() + { + return $this->name; + } }