Symfony 如何从JMS序列化程序获取始终数组?

Symfony 如何从JMS序列化程序获取始终数组?,symfony,doctrine,fosrestbundle,jmsserializerbundle,Symfony,Doctrine,Fosrestbundle,Jmsserializerbundle,我在rest中使用JMS序列化程序 这是我来自Rest控制器的代码。其返回的json或数组(服务器、本地主机)。如何获得始终数组响应?我找到了答案 /** * This function is used to get all Stopes. * * @ApiDoc( * resource=true, * section="Stop", * description="This function is used to get all Stopes", * statusCodes

我在rest中使用JMS序列化程序

这是我来自Rest控制器的代码。其返回的json或数组(服务器、本地主机)。如何获得始终数组响应?

我找到了答案

/**
 * This function is used to get all Stopes.
 *
 * @ApiDoc(
 *  resource=true,
 *  section="Stop",
 *  description="This function is used to get all Stopes",
 *  statusCodes={
 *         200="Returned when successful",
 *         404="Returned when the Stop is not found"
 *     }
 * )
 *
 * @return mixed
 * @Rest\View(serializerGroups={"main"})
 */
public function cgetAction()
{
    $em = $this->getDoctrine()->getManager();
    $stopes = $em->getRepository(self::ENTITY)->findAll();

    return $stopes;
}

这是已知的限制。我从来都不知道作者为什么不愿意包含pull请求,但是有一些
JMSSerializer
实现了这一点……太棒了!当您将
原则
的代理类作为成员时,请注意这种行为;)另外,我刚刚找到了几个月前我咨询过的这个讨论:
 /**
 * This function is used to get all Stopes.
 *
 * @ApiDoc(
 *  resource=true,
 *  section="Stop",
 *  description="This function is used to get all Stopes",
 *  statusCodes={
 *         200="Returned when successful",
 *         404="Returned when the Stop is not found"
 *     }
 * )
 *
 * @return mixed
 * @Rest\View(serializerGroups={"main"})
 */
public function cgetAction()
{
    $em = $this->getDoctrine()->getManager();
    $stopes = $em->getRepository(self::ENTITY)->findAll();


    return array_values($stopes);
}