Ejemplo n.º 1
0
 public function serializerAction()
 {
     $article = new Article();
     $article->setPath('/foo');
     $article->setTitle('Example use of the default handlers');
     $article->setBody("Read up on JMSSerializerBundle to see how what other handlers exist ");
     $view = new View();
     $view->setData($article);
     $context = new SerializationContext();
     $context->setVersion('2.1');
     $context->setGroups(array('data'));
     $view->setSerializationContext($context);
     return $this->viewHandler->handle($view);
 }
Ejemplo n.º 2
0
 /**
  * Gets or creates a JMS\Serializer\SerializationContext and initializes it with
  * the view exclusion strategies, groups & versions if a new context is created
  *
  * @param View $view
  *
  * @return SerializationContext
  */
 public function getSerializationContext(View $view)
 {
     $context = $view->getSerializationContext();
     if (null === $context) {
         $context = new SerializationContext();
         $groups = $this->container->getParameter('fos_rest.serializer.exclusion_strategy.groups');
         if ($groups) {
             $context->setGroups($groups);
         }
         $version = $this->container->getParameter('fos_rest.serializer.exclusion_strategy.version');
         if ($version) {
             $context->setVersion($version);
         }
     }
     return $context;
 }