Skip to content

Commit

Permalink
Merge pull request #345 from emilien-puget/patch-1
Browse files Browse the repository at this point in the history
[doc] Default group informations
  • Loading branch information
schmittjoh committed Sep 22, 2014
2 parents da86234 + c3cb584 commit d1cb450
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions doc/cookbook/exclusion_strategies.rst
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,21 @@ You can achieve that by using the ``@Groups`` annotation on your properties.
/** @Groups({"details"}) */
private $comments;
private $createdAt;
}
You can then tell the serializer which groups to serialize in your controller::

use JMS\Serializer\SerializationContext;

$serializer->serialize(new BlogPost(), 'json', SerializationContext::create()->setGroups(array('list')));
//will output $id, $title and $nbComments.

$serializer->serialize(new BlogPost(), 'json', SerializationContext::create()->setGroups(array('Default', 'list')));
//will output $id, $title, $nbComments and $createdAt.

Limiting serialization depth of some properties
-----------------------------------------------
Expand Down

0 comments on commit d1cb450

Please sign in to comment.