Skip to content

Commit 3514fbf

Browse files
committed
Merge branch '3.4' into 4.4
* 3.4: Minor: Add linebreak. refs #13432 Added an example Entity for Serializer
2 parents 735dc40 + 5c8861b commit 3514fbf

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

serializer.rst

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,46 @@ To use annotations, first add support for them via the SensioFrameworkExtraBundl
150150
$ composer require sensio/framework-extra-bundle
151151
152152
Next, add the :ref:`@Groups annotations <component-serializer-attributes-groups-annotations>`
153-
to your class and choose which groups to use when serializing::
153+
to your class::
154+
155+
// src/Entity/Product.php
156+
namespace App\Entity;
157+
158+
use Doctrine\ORM\Mapping as ORM;
159+
use Symfony\Component\Serializer\Annotation\Groups;
160+
161+
/**
162+
* @ORM\Entity()
163+
*/
164+
class Product
165+
{
166+
/**
167+
* @ORM\Id
168+
* @ORM\GeneratedValue
169+
* @ORM\Column(type="integer")
170+
* @Groups({"show_product", "list_product"})
171+
*/
172+
private $id;
173+
174+
/**
175+
* @ORM\Column(type="string", length=255)
176+
* @Groups({"show_product", "list_product"})
177+
*/
178+
private $name;
179+
180+
/**
181+
* @ORM\Column(type="integer")
182+
* @Groups({"show_product"})
183+
*/
184+
private $description;
185+
}
186+
187+
You can now choose which groups to use when serializing::
154188

155189
$json = $serializer->serialize(
156-
$someObject,
157-
'json', ['groups' => 'group1']
190+
$product,
191+
'json',
192+
['groups' => 'show_product']
158193
);
159194

160195
.. tip::

0 commit comments

Comments
 (0)