symfony: [Serializer] Groups not working

Symfony version(s) affected: 4.4.x

Description
Hi,

I’m using groups to serialize data but it’s not always working.

For example :

    /**
     * @ORM\Column(type="array", nullable=true)
     * @Groups({"me_user", "write_user"})
     */
    protected $register_purposes;
        //return serialized data
        $serializedEntity = $this->container->get('serializer')->serialize($users, 'json', array('groups' => ['me_user']));
        return new Response($serializedEntity, 200, ['Content-Type' => 'application/json']);

Won’t work until I passed the field with public access. So : public $register_purposes;

Any idea why ?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (6 by maintainers)

Most upvoted comments

@pesseyjulien i’m sorry but this change could not be added for several reason :

@pesseyjulien it seems to be the name of your property ‘$register_purposes’ try with ‘registerPurposes’ it seems not resolving the snake case i dont kown why i’m finding