Builds the response.

@param array  $data
@param string $serializationGroup

@return Response
543661
protected function buildResponse(array $data, $serializationGroup = 'Default')
    {
        $response = new Response($this->serialize($data, $serializationGroup));
        $response->headers->set('Content-Type', 'application/json');

        return $response;
    }
230388
protected function createResponse($data = null)
    {
        $view = new View();
        $view->setData($data);

        $context = $view->getSerializationContext();
        if ($this->serialization->isCheckDepth()) {
            $context->enableMaxDepthChecks();
        }
        $context->setGroups($this->serialization->getGroups());

        $view->setSerializationContext($context);

        return $this->handleView($view);
    }
619073
public function serialize($data) {
        $list = $this->recursive($data, 1);
        return $this->renderWith(['Result', 'Controller'], ['Data' => \ArrayList::create($list)]);
    }
874694
private function deserializeData($data)
    {
        $result = $this->get('jms_serializer')->deserialize(
            $data,
            $this->getTargetGroupRepository()->getClassName(),
            'json',
            DeserializationContext::create()
                ->setSerializeNull(true)
        );

        return $result;
    }
847766
protected function json($data, int $status = 200, array $headers = [], array $context = []): JsonResponse
    {
        if ($this->container->has('serializer')) {
            $json = $this->container->get('serializer')->serialize($data, 'json', array_merge([
                'json_encode_options' => JsonResponse::DEFAULT_ENCODING_OPTIONS,
            ], $context));

            return new JsonResponse($json, $status, $headers, true);
        }

        return new JsonResponse($data, $status, $headers);
    }
596407
public function withJsonBody($data, SerializationContext $context = null)
    {
        if (is_string($data)) {
            $json = $data;
        } else {
            $json = SerializerBuilder::create()->build()->serialize($data, 'json', $context);
        }
        $this->withBody($json);

        return $this;
    }
1275393
protected function createFormGroup(array $data = null)
    {
        $type = $this->defaultGroupType();

        if (isset($data['template'])) {
            unset($data['template']);
        }

        $group = $this->formGroupFactory()->create($type);
        $group->setForm($this);

        if ($group instanceof ObjectContainerInterface) {
            if (empty($group->objType())) {
                $group->setObjType($this->objType());
            }

            if (empty($group->objId()) && !empty($this->objId())) {
                $group->setObjId($this->objId());
            }
        }

        if ($data !== null) {
            $group->setData($data);
        }

        $group['show_header'] = $this->showHeader();
        $group['show_title'] = $this->showTitle();

        return $group;
    }
333905
public function found(array $data): Response
    {
        $this->response->setBody(json_encode(['data' => $data]));
        return $this->response;
    }
38007
public function createObjectStateGroupListFromData(array $data)
    {
        $objectStateGroups = array();

        foreach ($data as $objectStateGroupData) {
            $objectStateGroups[] = $this->createObjectStateGroupFromData($objectStateGroupData);
        }

        return $objectStateGroups;
    }
1040611
public function parse(array $data, ParsingDispatcher $parsingDispatcher)
    {
        $contentTypeGroupReferences = array();
        foreach ($data['ContentTypeGroupRef'] as $groupData) {
            $contentTypeGroupReferences[] = $groupData['_href'];
        }

        return new Values\ContentTypeGroupRefList(
            $this->contentTypeService,
            $data['_href'],
            $contentTypeGroupReferences
        );
    }
1193326
public function createGroup(Api\GroupCreate $group)
    {
        $json = Serialize::group($group);
        $result = $this->_post($this->_url('/groups'), $json);
        return Deserialize::groupResponse($result);
    }
1029366
public function updateGroup($groupId, Api\GroupUpdate $group)
    {
        $json = Serialize::groupUpdate($group);
        $result = $this->_post($this->_groupUrl($groupId), $json);
        return Deserialize::groupResponse($result);
    }
1351789
public function addSerializerGroup($group)
    {
        if (is_array($group)) {
            $this->serializerGroups = array_merge(
                $this->serializerGroups,
                $group
            );
        } else {
            $this->serializerGroups[$group] = $group;
        }
    }
744103
public static function jsonUnserialize($data) {

		$report = null;

		if (!is_array($data)) {
			$data = (Array) json_decode($data, true);
		}

		if (count(array_intersect(['type', 'message', 'data'], array_keys($data))) == 3) {
			$report = new self($data['type'], $data['message'], $data['data']);
			if (isset($data['children']) && is_array($data['children'])) {
				foreach ($data['children'] as $child) {
					$report->add(static::jsonUnserialize($child));
				}
			}
		}

		return $report;
	}
126305
public function serializeWithGroup($data, $format, $group)
    {
        $serializer = $this->evaluator->getSerializer();

        return $serializer->serialize($data, $format, SerializationContext::create()->setGroups([$group]));
    }
316447
private function buildGroup(FormGroup $group, array $names = [], $data = [], array $errors = [])
    {
        $html = '';

        // Get groupname
        $group_name = $group->getName();

        // If group has a name, add it to the names array
        if ($group_name === 0 || !empty($group_name)) {
            $names[] = $group_name;
        }

        // Get grouperrors
        $group_errors = ($group_name === 0 || !empty($group_name)) && !empty($errors[$group_name]) ? $errors[$group_name] : $errors;

        // Get group data
        $group_data = ($group_name === 0 || !empty($group_name)) && !empty($data[$group_name]) ? $data[$group_name] : $data;

        // Build elements
        $elements = $group->getElements();

        // Get the control size set for this group
        $control_size = $group->getControlSize();

        /* @var $element \Core\Html\FormDesigner\FormElement */
        foreach ($elements as $element) {

            $builder = new ControlBuilder();

            $content = $element->getContent();

            switch ($element->getType()) {

                case 'control':

                    if (!empty($control_size)) {
                        $content->setControlSize($control_size);
                    }

                    // Get control name
                    $name = $content->getName();

                    // Set control id
                    if (empty($content->getId())) {

                        // Create control id elements
                        $id = $this->namespace . '-';

                        if (!empty($names)) {
                            $id .= implode('-', $names);
                        }

                        $id .= '-' . empty($name) ? uniqid('control-') : $name;

                        $content->setId($id);
                    }

                    // Create control name for bound controls...
                    if ($content->isBound()) {

                        if (empty($name)) {
                            Throw new FormDesignerException(sprintf('Bound controls without a name are not allowed. %s', print_r($content, true)));
                        }

                        // Create name parts based on current group names
                        $pieces = array_map(function ($name) {
                            return '[' . $name . ']';
                        }, $names);

                        $pieces[] = '[' . $name . ']';

                        $content->setName($this->namespace . implode('', $pieces));
                    }
                    else {

                        // ...and remove name from the unbound ones!
                        $content->removeName();
                    }

                    // Any errors?
                    if (!empty($group_errors[$name])) {
                        $builder->setErrors($group_errors[$name]);
                    }

                    if (isset($group_data[$name])) {

                        switch (true) {
                            case ($content instanceof Checkbox):
                                if ($content->getValue() == $group_data[$name]) {
                                    $content->isChecked();
                                }
                                break;

                            default:
                                if (empty($content->getValue()) && method_exists($content, 'setValue')) {
                                    $content->setValue($group_data[$name]);
                                }
                                break;
                        }
                    }

                    // Handle buttons
                    if ($content instanceof Button) {

                        // Add needed ajax data attribute
                        if ($this->getSendMode() == 'ajax') {
                            $content->addData('ajax');
                        }

                        // Submit buttons need the id and action of and for the form to submit
                        if ($content->isSubmit()) {
                            $content->setFormId($this->html->getId());
                            $content->setFormAction($this->html->getAttribute('action'));
                            $content->setFormMethod('post');
                        }
                    }

                    $builder->setControl($content);
                    $builder->setDisplayMode($this->display_mode, $this->grid_size, $this->label_width);

                    // Build control
                    $html .= $builder->build();

                    break;

                case 'collection':

                    /* @var $builder \Core\Html\FormDesigner\ControlBuilder */
                    $builder = $this->di->instance(__NAMESPACE__ . '\ControlBuilder');

                    foreach ($content->getControls() as $control) {

                        if ($control instanceof AbstractForm) {
                            $builder->setControl($control);
                            $content->addInner($builder->build());
                        }
                        else {
                            $content->addInner($control->build());
                        }
                    }

                    $content->clearControls();

                    $html .= $content->build();

                    break;

                case 'factory':
                    $html .= $content->build();
                    break;

                case 'html':
                    $html .= $content;
                    break;

                case 'group':
                    $html .= $this->buildGroup($content, $names, $group_data, $group_errors);
                    break;
            }
        }

        $group->html->addInner($html);

        return $group->html->build();
    }
1330528
public function addGroups($data){

        foreach ($data as $k=>$v){
            $groups[] = ['name' => $k , 'title' => $v];
        }
        $this->formGroups = $groups;
        return $this;
    }