Estou realizando o select dos dados da classe que criei porém não esta retornando em Json
<?php
namespace App\Controller;
use App\Entity\Marca;
use App\Helper\MarcaFactory;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Validator\Constraints\Collection;
class MarcaController extends AbstractController
{
/**
* @var EntityManagerInterface
*/
private $entityManager;
/**
* @var MarcaFactory
*/
private $marcaFactory;
public function __construct(
EntityManagerInterface $entityManager,
MarcaFactory $marcaFactory)
{
$this->entityManager = $entityManager;
$this->marcaFactory = $marcaFactory;
}
/**
* @Route("/marca", methods={"POST"})
*/
public function salvar(Request $request): Response
{
$corpoRequisicao = $request->getContent();
$dadosEmJson = json_decode($corpoRequisicao);
$marca = new Marca();
$marca->setMarca($dadosEmJson->marca);
$this->entityManager->persist($marca);
$this->entityManager->flush();
return new JsonResponse($marca);
}
/**
* @Route("/marca", methods={"GET"})
*/
public function listar(): Response
{
//return new JsonResponse($this->repository->findAll());
$repositorioDeMarcas = $this
->getDoctrine()
->getRepository(Marca::class);
$marcaList = $repositorioDeMarcas->findAll();
foreach ($marcaList as $marca){
echo($marca->getMarca() . "\n");
}
return new JsonResponse($marcaList);
}
}
O retorno gerado no browser sai assim:
Coca-Cola Skol Aee Aee Aee [{},{},{},{},{}]
Com echo sai ok, por meio do JsonResponse vazio.