@@ -315,6 +315,26 @@ Then, create your groups definition:
315
315
// ...
316
316
}
317
317
318
+ .. code-block :: php-attributes
319
+
320
+ namespace Acme;
321
+
322
+ use Symfony\Component\Serializer\Annotation\Groups;
323
+
324
+ class MyObj
325
+ {
326
+ #[Groups(['group1', 'group2'])]
327
+ public $foo;
328
+
329
+ #[Groups(['group3'])]
330
+ public function getBar() // is* methods are also supported
331
+ {
332
+ return $this->bar;
333
+ }
334
+
335
+ // ...
336
+ }
337
+
318
338
.. code-block :: yaml
319
339
320
340
Acme\MyObj :
@@ -437,6 +457,20 @@ Option 1: Using ``@Ignore`` Annotation
437
457
public $bar;
438
458
}
439
459
460
+ .. code-block :: php-attributes
461
+
462
+ namespace App\Model;
463
+
464
+ use Symfony\Component\Serializer\Annotation\Ignore;
465
+
466
+ class MyClass
467
+ {
468
+ public $foo;
469
+
470
+ #[Ignore]
471
+ public $bar;
472
+ }
473
+
440
474
.. code-block :: yaml
441
475
442
476
App\Model\MyClass :
@@ -658,6 +692,25 @@ defines a ``Person`` entity with a ``firstName`` property:
658
692
// ...
659
693
}
660
694
695
+ .. code-block :: php-attributes
696
+
697
+ namespace App\Entity;
698
+
699
+ use Symfony\Component\Serializer\Annotation\SerializedName;
700
+
701
+ class Person
702
+ {
703
+ #[SerializedName('customer_name')]
704
+ private $firstName;
705
+
706
+ public function __construct($firstName)
707
+ {
708
+ $this->firstName = $firstName;
709
+ }
710
+
711
+ // ...
712
+ }
713
+
661
714
.. code-block :: yaml
662
715
663
716
App\Entity\Person :
@@ -1218,6 +1271,20 @@ Here, we set it to 2 for the ``$child`` property:
1218
1271
// ...
1219
1272
}
1220
1273
1274
+ .. code-block :: php-attributes
1275
+
1276
+ namespace Acme;
1277
+
1278
+ use Symfony\Component\Serializer\Annotation\MaxDepth;
1279
+
1280
+ class MyObj
1281
+ {
1282
+ #[MaxDepth(2)]
1283
+ public $child;
1284
+
1285
+ // ...
1286
+ }
1287
+
1221
1288
.. code-block :: yaml
1222
1289
1223
1290
Acme\MyObj :
@@ -1528,6 +1595,23 @@ and ``BitBucketCodeRepository`` classes:
1528
1595
// ...
1529
1596
}
1530
1597
1598
+ .. code-block :: php-attributes
1599
+
1600
+ namespace App;
1601
+
1602
+ use App\BitBucketCodeRepository;
1603
+ use App\GitHubCodeRepository;
1604
+ use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
1605
+
1606
+ #[DiscriminatorMap(typeProperty: 'type', mapping: [
1607
+ 'github' => GitHubCodeRepository::class,
1608
+ 'bitbucket' => BitBucketCodeRepository::class,
1609
+ ])]
1610
+ interface CodeRepository
1611
+ {
1612
+ // ...
1613
+ }
1614
+
1531
1615
.. code-block :: yaml
1532
1616
1533
1617
App\CodeRepository :
0 commit comments