title: Serializer and DateTime format - how to get only string with date
body: <p>I writing a simple financial application. In this moment I working on API and created first method with GetAll() functionality that give me every record from table.
  I've got 2 questions:</p>
  <p><strong>Question number one:</strong></p>
  <p>I using serializer from Serializer Component and got this view:</p>
  <p><a href="https://i.stack.imgur.com/aWW77.png" rel="nofollow noreferrer">my_api_response_view</a></p>
  <p>How to get string date format (for example - 2022-01-05) with serializer? I tried with DateTimeNormalizer::FORMAT_KEY but it doesn't work.</p>
  <p><strong>Question number two:</strong></p>
  <p>Is there any instruction where to put Serializer encoders and normalizers and how to implement serializer object in controller? In documentation I can't see anything about where to put serializer components.</p>
  <p>My Controller class with Serializer code:</p>
  <pre><code>&lt;?php
  
  namespace App\Controller\InFlow;
  
  use App\Entity\InFlow\InFlow;
  use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  use Symfony\Component\HttpFoundation\Response;
  use Symfony\Component\Routing\Annotation\Route;
  use Doctrine\ORM\EntityManagerInterface;
  use Symfony\Component\HttpFoundation\JsonResponse;
  use Symfony\Component\Serializer\Serializer;
  use Symfony\Component\Serializer\Encoder\JsonEncoder;
  use Symfony\Component\Serializer\Encoder\XmlEncoder;
  use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
  use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
  
  
  class InFlowController extends AbstractController
  {
      #[Route('/in/flow', name: 'app_in_flow')]
      public function index(): Response
      {
          return $this-&gt;json([
              'message' =&gt; 'Welcome to your new controller!',
              'path' =&gt; 'src/Controller/InFlowController.php',
          ]);
      }
  
      #[Route('/inflows', name: 'get_all_inflows')]
      public function getAll(EntityManagerInterface $em): JsonResponse {
  
          $encoders = [new XmlEncoder(), new JsonEncoder()];
          $normalizers = [new ObjectNormalizer()];
          $serializer = new Serializer($normalizers, $encoders);
          $inFlows = $em-&gt;getRepository(InFlow::class)-&gt;findAll();
          $jsonContent = $serializer-&gt;serialize($inFlows, 'json', [DateTimeNormalizer::FORMAT_KEY =&gt; 'Y-m-d H:i:s']);
          return new JsonResponse(['Data'=&gt;json_decode($jsonContent)], 200);
      }
  }
  </code></pre>
  <p>My Entity Class:</p>
  <pre><code>&lt;?php
  
  namespace App\Entity\InFlow;
  
  use App\Repository\InFlowRepository;
  use Doctrine\ORM\Mapping as ORM;
  
  #[ORM\Entity(repositoryClass: InFlowRepository::class)]
  class InFlow
  {
      #[ORM\Id]
      #[ORM\GeneratedValue]
      #[ORM\Column(type: 'integer')]
      private $id;
  
      #[ORM\Column(type: 'string', length: 255)]
      private $in_flow_name;
  
      #[ORM\Column(type: 'float')]
      private $in_flow_value;
  
      #[ORM\Column(type: 'datetime')]
      private $in_flow_date;
  
      #[ORM\Column(type: 'string', length: 255, nullable: true)]
      private $in_flow_comment;
  
      public function getId(): ?int
      {
          return $this-&gt;id;
      }
  
      public function getInFlowName(): ?string
      {
          return $this-&gt;in_flow_name;
      }
  
      public function setInFlowName(string $in_flow_name): self
      {
          $this-&gt;in_flow_name = $in_flow_name;
  
          return $this;
      }
  
      public function getInFlowValue(): ?float
      {
          return $this-&gt;in_flow_value;
      }
  
      public function setInFlowValue(float $in_flow_value): self
      {
          $this-&gt;in_flow_value = $in_flow_value;
  
          return $this;
      }
  
      public function getInFlowDate(): ?\DateTimeInterface
      {
          return $this-&gt;in_flow_date;
      }
  
      public function setInFlowDate(\DateTimeInterface $in_flow_date): self
      {
          $this-&gt;in_flow_date = $in_flow_date;
  
          return $this;
      }
  
      public function getInFlowComment(): ?string
      {
          return $this-&gt;in_flow_comment;
      }
  
      public function setInFlowComment(?string $in_flow_comment): self
      {
          $this-&gt;in_flow_comment = $in_flow_comment;
  
          return $this;
      }
  }
  </code></pre>
  <p>Thank You!</p>