security->isGranted('ROLE_ADMIN') || $this->security->isGranted('ROLE_USER'))) { throw new AccessDeniedHttpException('Must be user or admin to create a stored object'); } $object = new StoredObject(); $this->entityManager->persist($object); $this->entityManager->flush(); return new JsonResponse( $this->serializer->serialize($object, 'json', [AbstractNormalizer::GROUPS => ['read']]), json: true ); } }