Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8991589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:45:50+00:00 2026-06-15T22:45:50+00:00

I’m using Symfony2 and JMSSerializerBundle to build an API. The system that JMSSerializer provides

  • 0

I’m using Symfony2 and JMSSerializerBundle to build an API. The system that JMSSerializer provides to set different ways of serializing objects using groups is quite useful, however, I’m missing a way to specify which group do you want to serialize in every parameter. Example:

I have an article that is related to a user (author). Articles as well as users can be serialized as “list” or as “details”, however, I want the users to be serialized as “list” always that they are retrieved from the article (because “details” group is reserved to be used to fetch the user and just the user). The problem is that if I set the serializer as “details”, then the author is also serialized as “details”.

In my mind, the code should be something like:

/**
 * @var SCA\APIBundle\Entity\User
 * @Groups({"list" => "list", "details" => "list"})
 */
private $author;

where the key of the array indicates the way the parent should be serialized, and the value indicates the way the child should be serialized.

Any clue how can I achieve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T22:45:51+00:00Added an answer on June 15, 2026 at 10:45 pm

    It should not be done on the composed object but on the composition.

    In your case, I suppose you have something like that:

    class Article
    {
        /**
         * @var User
         * @Groups({"list", "details"})
         */
        private $author;
    }
    
    
    class User
    {
        private $firstName;
        private $lastName;
    }
    

    So if you want to expose the firstName property when serializing the composed object, you need to define the same group in the User object.

    It becomes:

    class Article
    {
        /**
         * @var User
         * @Groups({"list", "details"})
         */
        private $author;
    }
    
    
    class User
    {
        /*
         * @Groups({"list"})
         */
        private $firstName;
        private $lastName;
    }
    

    If you need more control, you may define more explicit groups, like “article-list”, “user-firstname”, “user-list-minimal”, etc.

    It is up to you to decide the best strategy to adopt.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I've tracked down a weird MySQL problem to the two different ways I was
I'm making a simple page using Google Maps API 3. My first. One marker
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.