Deserialize return array
dev-yann opened this issue · 0 comments
dev-yann commented
Hi, I would like to perform a recursive deserialization. But the problem is that the function return an array instead of object.
services.yaml =>
# Add DateTime Normalizer to Dunglas' Doctrine JSON ODM Bundle
dunglas_doctrine_json_odm.serializer:
class: Dunglas\DoctrineJsonOdm\Serializer
arguments:
- ['@dunglas_doctrine_json_odm.normalizer.array', '@serializer.normalizer.datetime', '@dunglas_doctrine_json_odm.normalizer.object']
- ['@serializer.encoder.json']
public: true
$userOrder = $serializer->deserialize($request->getContent(), UserOrder::class, 'json');
$userorder is an array instead of object.
this is my entity =>
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\MaxDepth;
/**
* @ORM\Entity
*/
class UserOrder
{
/**
* @ORM\Id()
* @ORM\GeneratedValue(strategy="UUID")
* @ORM\Column(type="guid", unique=true)
*/
private $id;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $status;
/**
* @var OrderDetail[] | ArrayCollection
* @ORM\OneToMany(targetEntity=OrderDetail::class, mappedBy="order", orphanRemoval=true, cascade={"persist"})
*/
private $orderDetails;
....
I can get an object with this instruction in my controller :
$normalizer = new ObjectNormalizer(null, null, null, new ReflectionExtractor());
$serializer = new Serializer([new ArrayDenormalizer(), $normalizer], [new JsonEncoder()]);
$userOrder = $serializer->deserialize($request->getContent(), UserOrder::class, 'json');
But I would like to use the serializer service directly, is there any way for perform a recursive deserialization with doctrine-json-odm and get real object, not an array ? Thanks for your time