@param Request $request

@return JsonResponse

@throws \Exception
778537
public function checkAvailabilityAction(Request $request)
    {
        $response = ['available' => true];
        $translator = $this->get('translator');
        $repo = $this->getDoctrine()->getManager()->getRepository($request->get('className'));

        $object = $repo->findOneBy([$request->get('fieldName') => $request->get('fieldValue')]);

        if ($object != null) {
            $response['available'] = false;
            $response['error'] = $this->get('translator')->trans('already exists');

            if ($request->get('returnLink') == true) {
                $adminPool = $this->container->get('sonata.admin.pool');
                $admin = $adminPool->getAdminByAdminCode($request->get('adminCode'));

                $response['link'] = $admin->generateObjectUrl('edit', $object);
                $response['message'] = $translator->trans('Edit object');
            }
        }

        return new JsonResponse($response, 200);
    }
1050194
public function handle(Request $request)
	{
		// execute response
		$response = $this->next($request);

		// only do this if user wants it expanded
		if (!$expand = $request->getVar('expand', null))
		{
			return $response;
		}

		// normalize keys
		$expandKeys = $this->normalizeExpandKeys($expand);

		// only do on json data
		if (!$response->isJson())
		{
			return $response;
		}

		// get the response content and json decode
		$content = json_decode($response->getContent());

		// make sure to handle array different then a single object
		if (is_array($content))
		{
			// loop through each item in array and covert dates
			foreach ($content as $key => $value)
			{
				$content[$key] = $this->convertExpandKeysInObjects($expandKeys, $value);
			}
		}
		else
		{
			// convert single object dates
			$content = $this->convertExpandKeysInObjects($expandKeys, $content);
		}

		// set the response content to modified content
		$response->setContent(json_encode($content));

		// return response
		return $response;
	}
363623
public function ajaxControllerAction(Request $request)
    {
        $operation = $request->request->get('operation') ? $request->request->get('operation') : $request->query->get(
            'operation'
        );

        if (!$operation) {
            throw new NotFoundHttpException();
        }

        return new JsonResponse($this->$operation());
    }
1328229
public function send(Request $request)
    {
        $response     = new SearchResponse();
        $httpRequest  = $this->createHttpRequest($request);
        $httpResponse = $this->client->send($httpRequest);
        $json         = $httpResponse->json();
        $result       = $json['response'];

        $response->docs     = $result['docs'];
        $response->numFound = $result['numFound'];
        $response->maxScore = $result['maxScore'];
        $response->docs     = array_map([$this, 'docToArray'], $result['docs']);

        return $response;
    }
875365
public function handle(Request $request)
    {
        try {
            $restRequest = new RestRequest($this->config, $request->getMethod(), $request->getUri(), $request->getContent());
            $restResponse = $this->adapter->processRequest($restRequest);
        } catch (\Exception $e) {
            if (true === $this->debugEnabled()) {
                throw $e;
            }
            $restResponse = $this->adapter->handleException($e);
        }
        return new Response($restResponse->getContent(), $restResponse->getStatus(), $restResponse->getHeaders());
    }
1239118
public function handleAction(Request $request): Response
    {
        $extras = $request->request->get('extras', []);

        if (!$this->hashHandler->verify($extras['worker'] ?? [], false)) {
            return JsonResponse::create(['invalid' => true, 'message' => 'Invalid hash verify.'], 500);
        }

        try {
            $result = $this->bus->dispatch($this->decoder->decode([
                'body' => $request->getContent(),
                'headers' => ['type' => $request->headers->get('x-chang-msg-type')],
            ])->with(new ReceivedStamp()));
        } catch (\Exception $e) {
            return JsonResponse::create(['message' => $e->getMessage()], 500);
        }

        $this->hashHandler->flush();

        if ($result instanceof AbstractMessage && $result->isExpired()) {
            return JsonResponse::create(['expired' => true, 'message' => 'Message was expired.'], 500);
        }

        return JsonResponse::create([], 200);
    }
573742
public function postAction(Request $request)
    {
        try {
            return $this->createJsonResponse($this->get('oauth.server')->grant(
                $this->getRequestData($request, 'snakelize')
            ));
        } catch (InvalidGrantException $e) {
            return new JsonResponse('Unavailable to create access token : bad credentials.', 401);
        } catch (\InvalidArgumentException $e) {
            return new JsonResponse('Invalid or missing fields for grant type.', 400);
        }
    }
633354
public function replaceURLAction(Request $request)
    {
        $response = new JsonResponse();

        $response->setData(['text' => $this->urlHelper->replaceUrl($request->get('text'))]);

        return $response;
    }
1342111
public function getConfiguration(Request $request): JsonResponse
    {
        $domain = $request->query->get('domain');

        if (!$domain) {
            throw new MissingRequestParameterException('domain');
        }

        return new JsonResponse($this->configurationService->getConfiguration($domain));
    }
1193222
public function listAction(Request $request)
    {
        return new JsonResponse(
            $this->finder->search(
                'UJM\ExoBundle\Entity\Item\Item',
                $request->query->all(),
                [Transfer::INCLUDE_SOLUTIONS, Transfer::INCLUDE_ADMIN_META]
            )
        );
    }
454099
private function createNotFoundResponse($request, $exception)
    {
        $message = $exception->getMessage();
        if (empty($message)) {
            $message = 'Uri ' . $request->getRequestUri() . ' could not be found';
        }

        return new JsonResponse(
            [
                'status'  => 'ERROR',
                'message' => $message
            ],
            JsonResponse::HTTP_NOT_FOUND
        );
    }
253297
private function requestToJson($request)
  {
    $jsonRequest = null;
    try {
      $jsonRequest = $this->serializer->serialize($request, 'json');
    } catch (RuntimeException $e) {
      throw new RuntimeException('Unable to serialize request ' . var_dump($request));
    }

    return $jsonRequest;
  }
403480
protected function call($request)
    {
        if(!isset($request['query']))
        {
            $request['query'] = [];
        }

        $method  = 'GET';
        $headers = $this->getHeaders();
        $query   = http_build_query($request['query']);
        $url     = "{$this->domain}/{$request['route']}?$query";

        try {
            $request = $this->getClient()->request($method, $url, [
                'headers' => $headers
            ]);

            $response = $request->getBody()->getContents();

            return json_decode($response, true);

        } catch (RequestException $e) {
            $response = $e->getResponse();
            $response = json_decode($response, true);
            return $response;
        } catch (\Exception $e) {
            return ['error' => $e->getCode(), 'error_description' => $e->getMessage()];
        }
    }
214392
public function handle(Request $request)
    {
        $response = new Response();
        $response = $this->executePassiveActions($request, $response);
        $response = $this->executeAction($request, $response);

        if ($response->isClientError() || $response->isServerError()) {
            return $this->handleError($request, $response);
        }

        return $response;
    }
1066856
public function updateAction(Request $request): JsonResponse
    {
        $id   = $request->request->get('id');
        $data = $request->request->get('product');
        
        try {
            $this->quickUpdateProduct($id, $data);
            $result = ['success' => $this->trans('product.flash.success.saved')];
        } catch (\Exception $e) {
            $result = ['error' => $e->getMessage()];
        }
        
        return $this->jsonResponse($result);
    }
733203
public function postAction(Request $request)
    {
        try {
            $filter = $this->getManager()->save(
                $request->request->all(),
                $this->getRequestParameter($request, 'locale', true),
                $this->getUser()->getId()
            );
            $view = $this->view($filter, 200);
        } catch (FilterDependencyNotFoundException $e) {
            $exception = new EntityNotFoundException($e->getEntityName(), $e->getId());
            $view = $this->view($exception->toArray(), 400);
        } catch (MissingFilterException $e) {
            $exception = new MissingArgumentException(self::$entityName, $e->getFilter());
            $view = $this->view($exception->toArray(), 400);
        } catch (MissingFilterAttributeException $e) {
            $exception = new MissingArgumentException(self::$entityName, $e->getAttribute());
            $view = $this->view($exception->toArray(), 400);
        } catch (ConditionGroupMismatchException $e) {
            $exception = new InvalidArgumentException(self::$groupConditionEntityName, $e->getId());
            $view = $this->view($exception->toArray(), 400);
        } catch (UnknownContextException $e) {
            $exception = new RestException($e->getMessage());
            $view = $this->view($exception->toArray(), 400);
        }

        return $this->handleView($view);
    }
410229
public function updateOrder(Request $request): JsonResponse
    {
        Category::rebuildTree(
            $request->input('tree')
        );

        $this->clearCache();

        $movedNode = Category::findOrFail(
            $request->input('moved')
        );

        dispatch(
            new RegenerateCategoryFullSlugs($movedNode)
        );

        return response()->json([
            'state' => 'success',
        ]);
    }