在"friendsofsymfony/rest-bundle": "~1.4",
中,我们在{1}}中设置了来自"jms/serializer-bundle": "^1.1.0",
的setSerializationContext,我们设置gropu并启用深度
return View::create()
->setStatusCode(200)
->setData($certificatesResponse)
->setSerializationContext(
SerializationContext::create()
->enableMaxDepthChecks()
->setGroups(array('certificates_by_parameters'))
);
在"friendsofsymfony/rest-bundle": "~1.4",
早期,我们为RestBundle中的View类提供了这个函数
/**
* Sets the serialization context.
*
* @param SerializationContext $serializationContext
*
* @return View
*/
public function setSerializationContext(SerializationContext $serializationContext)
{
$this->serializationContext = $serializationContext;
return $this;
}
在"friendsofsymfony/rest-bundle": "^2.0",
我找不到这个函数,如何在2.0版本中设置序列化上下文?
答案 0 :(得分:4)
你应该看看https://github.com/FriendsOfSymfony/FOSRestBundle/blob/master/UPGRADING-2.0.md。
==>
View::setSerializationContext and View::getSerializationContext have been removed. Use View::setContext and View::getContext together with the new Context class instead.
Before:
use JMS\Serializer\SerializationContext;
$view = new View();
$context = new SerializationContext();
$view->setSerializationContext($context);
$context = $view->getSerializationContext();
After:
use FOS\RestBundle\Context\Context;
$view = new View();
$context = new Context();
$view->setContext($context);
$context = $view->getContext();