JMS Serializer. Can not use context from yaml.file to serialize object with groups

43 Views Asked by At

jms/serializer-bundle: 5.4.0 and symfony project 6.4 I have in framework.yaml

...
    serializer:
        mapping:
            paths: ['%kernel.project_dir%/config/serialization']
...

In folder config/serialization I have a bunch of yaml files with configs (where they groups set). One of them:

App\Entity\SomeEntity:
  attributes:
    id:
      groups:
        - 'some_entity'
        - 'some_entity_with_name'
    code:
      groups:
        - 'some_entity'
        - 'some_entity_with_name'
    name:
      groups:
        - 'some_entity_with_name'

When I try to use serializer to get group "some_entity" I got this: "{}"

use JMS\Serializer\SerializerInterface;
use Doctrine\ORM\QueryBuilder;

    public function __construct(
        ManagerRegistry $registry,
        private readonly SerializerInterface $serializer,
    ) {}


$this->serializer->serialize($qb->getQuery()->getOneOrNullResult(), 'json', SerializationContext::create()->setGroups(['some_entity']))

How to say serializer to use context from yaml files? When I use $this->response($data, context: some_context); it works okey

I saw the documentation and there were nothing to explain this behavior.

0

There are 0 best solutions below