I am using Symfony2 and JMSSerializerBundle to create an API. The system that JMSSerializer provides for setting various ways to serialize objects using groups is very useful, however, I don’t have enough way to specify which group you want to serialize in each parameter. Example:
I have an article related to the user (author). Articles as well as users can be serialized as a “list” or “details”, however I want users to be serialized sequentially as a “list” so that they are retrieved from the article (since the group “details” is reserved for use to retrieve the user and user only). The problem is that if I set the serializer as "details", then the author is also serialized as "details".
In my opinion, the code should look something like this:
/** * @var SCA\APIBundle\Entity\User * @Groups({"list" => "list", "details" => "list"}) */ private $author;
where the array key indicates the way the parent element is serialized, and the value indicates the way that it should be serialized.
Any clue how can I achieve this?
php symfony jmsserializerbundle
Alejandro Pérez Dec 02 2018-12-12T00: 00Z
source share