开发者

Deserializer result to null symfony

I discover the serializer and deserializer.

I have an index.json file and I'm trying to deserializer.

The json_decode works (I have many tables as a result) however with the deserializer I have everything at null and I don't understand why. (I begin)

index.json:

[
  {
    "label": "VILLA GALLO-ROMAINE DU GROSSWALD",
    "lastUpdateDatatour开发者_如何学Pythonisme": "2022-09-24T04:00:46.397Z",
    "file": "0/00/10-000283ba-f94b-3bce-8f57-e5c10bec6cd4.json"
  },
  {
    "label": "ÉGLISE PAROISSIALE DE LA NATIVITÉ",
    "lastUpdateDatatourisme": "2022-08-07T04:02:23.588Z",
    "file": "0/00/10-0016e4ef-68b7-3e79-87c4-5a277e1a43ac.json"
  },
  {
    "label": "CHEZ LES P'TITS PAYSANS",
    "lastUpdateDatatourisme": "2022-11-20T06:05:43.206Z",
    "file": "0/00/10-001dc202-cf27-355f-8577-6ef3105bddec.json"
  },(...)

my class:

<?php

namespace App\Entity;

use App\Repository\IndexDataTourismeRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: IndexDataTourismeRepository::class)]
class IndexDataTourisme
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\Column(type: Types::TEXT)]
    private ?string $label = null;

    #[ORM\Column(length: 255)]
    private ?string $lastUpdateDatatourisme = null;

    #[ORM\Column(length: 255)]
    private ?string $file = null;

my controller:

class HomeController extends AbstractController
{
    #[Route('/home', name: 'app_home')]
    public function index(): Response
    {
        $encoders = [new XmlEncoder(), new JsonEncoder()];
        $normalizers = [new ObjectNormalizer()];

        $serializer = new Serializer($normalizers, $encoders);
 $person = $serializer->deserialize($data, IndexDataTourisme::class, 'json', [AbstractObjectNormalizer::SKIP_UNINITIALIZED_VALUES => false]);
        dd($person);
        return $this->render('home/index.html.twig', [
            'controller_name' => 'HomeController',
        ]);
    }

in my opinion it is a visible error for you, but I pass by without understanding... and also, if ever a new field is added to my index.json, I want my application to continue to work with the dezerializer.

I use symfony 6.2

thank you

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜