/**
  * Fill a jms context.
  *
  * @param ContextInterface $context
  * @param JMSContext       $newContext
  *
  * @return JMSContext
  */
 private function fillContext(ContextInterface $context, JMSContext $newContext)
 {
     foreach ($context->getAttributes() as $key => $value) {
         $newContext->attributes->set($key, $value);
     }
     if ($context instanceof VersionableContextInterface && null !== $context->getVersion()) {
         $newContext->setVersion($context->getVersion());
     }
     if ($context instanceof GroupableContextInterface) {
         $groups = $context->getGroups();
         if (!empty($groups)) {
             $newContext->setGroups($context->getGroups());
         }
     }
     if ($context instanceof MaxDepthContextInterface && null !== $context->getMaxDepth()) {
         $newContext->enableMaxDepthChecks();
     }
     if ($context instanceof SerializeNullContextInterface && null !== $context->getSerializeNull()) {
         $newContext->setSerializeNull($context->getSerializeNull());
     }
     return $newContext;
 }