Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deserialize return array #91

Open
dev-yann opened this issue Aug 17, 2020 · 0 comments
Open

Deserialize return array #91

dev-yann opened this issue Aug 17, 2020 · 0 comments

Comments

@dev-yann
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant