File tree Expand file tree Collapse file tree 1 file changed +37
-3
lines changed Expand file tree Collapse file tree 1 file changed +37
-3
lines changed Original file line number Diff line number Diff line change @@ -212,11 +212,45 @@ with the following configuration:
212212 ]);
213213
214214 Next, add the :ref: `@Groups annotations <component-serializer-attributes-groups-annotations >`
215- to your class and choose which groups to use when serializing::
215+ to your class::
216+
217+ // src/Entity/Product.php
218+ namespace App\Entity;
219+
220+ use Doctrine\ORM\Mapping as ORM;
221+ use Symfony\Component\Serializer\Annotation\Groups;
222+
223+ /**
224+ * @ORM\Entity()
225+ */
226+ class Product
227+ {
228+ /**
229+ * @ORM\Id
230+ * @ORM\GeneratedValue
231+ * @ORM\Column(type="integer")
232+ * @Groups({"show_product", "list_product"})
233+ */
234+ private $id;
235+
236+ /**
237+ * @ORM\Column(type="string", length=255)
238+ * @Groups({"show_product", "list_product"})
239+ */
240+ private $name;
241+
242+ /**
243+ * @ORM\Column(type="integer")
244+ * @Groups({"show_product"})
245+ */
246+ private $description;
247+ }
248+
249+ You can now choose which groups to use when serializing::
216250
217251 $json = $serializer->serialize(
218- $someObject ,
219- 'json', ['groups' => ['group1'] ]
252+ $product ,
253+ 'json', ['groups' => 'show_product' ]
220254 );
221255
222256In addition to the ``@Groups `` annotation, the Serializer component also
You can’t perform that action at this time.
0 commit comments