public function serializeContextFunction($context)
    {
        $json = array();

        foreach ($context as $key => $value) {
            if (!in_array($key, array('_parent', 'assetic', 'app')) && !preg_match('#sonata#', $key)) {
                try {
                    $serializedValue = $this->serializer->serialize($value, 'json');
                } catch (\JMS\Serializer\Exception\RuntimeException $ex) {
                    $serializedValue = json_encode($value, null, 2);
                }

                if (!empty($serializedValue)) {
                    $json[] = $this->serializer->serialize($key, 'json').':'.$serializedValue;
                }
            }
        }

        return '{'.implode(',', $json).'}';
    }