Symfony RestBundle with JMSSerialization setSerializationContext

1k Views Asked by At

in "friendsofsymfony/rest-bundle": "~1.4", we have setSerializationContext from "jms/serializer-bundle": "^1.1.0", in this context we set gropu and enable depth

        return View::create()
        ->setStatusCode(200)
        ->setData($certificatesResponse)
        ->setSerializationContext(
            SerializationContext::create()
                ->enableMaxDepthChecks()
                ->setGroups(array('certificates_by_parameters'))
        );

early in "friendsofsymfony/rest-bundle": "~1.4", we have this function for View class from RestBundle

    /**
 * Sets the serialization context.
 *
 * @param SerializationContext $serializationContext
 *
 * @return View
 */
public function setSerializationContext(SerializationContext $serializationContext)
{
    $this->serializationContext = $serializationContext;

    return $this;
}

In "friendsofsymfony/rest-bundle": "^2.0", I don't find this function, how to set serialized context in 2.0 version ?

1

There are 1 best solutions below

0
On

You should look here 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();