2

When I use findBy(), my data is automatically serialized.

$users = $this->getDoctrine()->getRepository('AppBundle:User')->findBy($params, $orderBy, $limit, $offset);


/**
 * @VirtualProperty
 * @SerializedName("catagory")
 * @Groups({"user"})
 */
public function getCategoryId()
{
    return $this->category->getId();
}

But when I use a custom MyfindBy() from my repository, the data is not automatically serialized. How can I automatically serialize the data?

SOLUTION :

Don't use select at the querybuilder.

Spawnrad
  • 445
  • 6
  • 18

1 Answers1

3

Please follow the documentation of symfony serializer from visiting this https://symfony.com/doc/current/components/serializer.html

(follow your desired verson documentation from there)

After getting your objecs by custom query u can pass the whole object array named $persons to the $jsonContent = $serializer->serialize($persons, 'json'); and send it to your response . after installing serializer components to your project .

please inform me if it not works for you.Thank you.

  • 1
    Hi thank you for your help but it doesn't work but i found the solution. I remove from my querybuilder the select. As soon as you i select, it will return an array and not serialize. – Spawnrad Jan 31 '18 at 21:49