question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Serialization Groups

See original GitHub issue

Hi there,

Quick question, I’ve tried looking through the documentation (including 2.0) but struggling to find the answer.

I have serialization groups set up on my Entity. This displays the required fields I want to see on my GET request, however I want to be able to display different fields on a custom GET Action that I’ve set up.

For example in the case of a Book entity that has a OneToMany to a Review Entity. In my out of the box GET request I have the serialization groups so that I don’t return any of the Reviews.

But I want to set up a Custom Action with say a route of book/1/reviews that brings back a few of the Book fields (name, isbn) and all the reviews linked. I know I can setup Groups per method type, but wondered if there was a way of setting a serialization group per GET request (such as one for the standard CRUD method and one for a Custom Action).

Hope that makes sense.

Kind regards Paul

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ppoundercommented, Oct 20, 2016
1reaction
soyukacommented, Oct 20, 2016

yes, see here

/**
 * @ApiResource(
 *     attributes={"normalization_context"={"groups"={"get"}}},
 *     itemOperations={
 *          "get"={"method"="GET"},
 *          "put"={"method"="PUT", "normalization_context"={"groups"={"put"}}}
 *     }
 * )
 */
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Use the Serializer (Symfony Docs)
Using Serialization Groups Attributes ... The value of the groups key can be a single string, or an array of strings. In addition...
Read more >
Selective serialization using serialization groups
It allows you to define different groups of attributes to serialize and deserialize. However, defining these groups without proper consideration ...
Read more >
Serialization Groups > API Platform - SymfonyCasts
The most common option by far is called "groups" , which you set to another array. ... use Symfony\Component\Serializer\Annotation\Groups; ... lines 9 -...
Read more >
The Serialization Process - API Platform
To configure the serialization groups of classes's properties, you must use directly the Symfony Serializer's configuration files or annotations.
Read more >
docs-2/serialization-groups-and-relations.md at master - GitHub
Serialization Groups and Relations. API Platform Core allows to choose which attributes of the resource are exposed during the normalization (read) and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found