【问题标题】:Symfony RestBundle with JMSSerialization setSerializationContextSymfony RestBundle 与 JMSSerialization setSerializationContext
【发布时间】:2017-01-05 15:57:25
【问题描述】:

"friendsofsymfony/rest-bundle": "~1.4", 中,我们从"jms/serializer-bundle": "^1.1.0", 中设置了序列化上下文,在此上下文中,我们设置了 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版本怎么设置序列化上下文?

【问题讨论】:

标签: php symfony fosrestbundle jmsserializerbundle


【解决方案1】:

你应该看这里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();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多