JMS Serializer ignores mappings for Knp Paginator

前端 未结 2 1726
礼貌的吻别
礼貌的吻别 2021-02-08 10:01

I have problem with exclusion of some KNP Paginator properties with JMS Serializer.

First, this is included in composer.json

...
\"jms/serializer-bundle\         


        
2条回答
  •  执笔经年
    2021-02-08 10:15

    Instead of serializing all the pagination object, try to serialize only the data and items, like this:

    $result = array(
      'data' => $pagination->getItems(),
      'meta' => $pagination->getPaginationData());
    
    return new Response(
        $serializer->serialize(
            $result,
            'json',
            SerializationContext::create()->setGroups(['Default'])
        ),
        Response::HTTP_OK,
        ['Content-Type' => 'application/json',]
    );
    

提交回复
热议问题