dunglas/doctrine-json-odm

Could not denormalize object of type "", no supporting normalizer found

dev-yann opened this issue · 4 comments

Hello 👋 and thanks for this bundle.
I can't get my user object with doctrine find method.
First of all this is my service.yaml and my model:

services:
    # default configuration for services in *this* file
    _defaults:
        autowire: true      # Automatically injects dependencies in your services.
        autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.

    #Add DateTime Normalizer
    dunglas_doctrine_json_odm.serializer:
        class: Symfony\Component\Serializer\Serializer
        arguments:
            - ['@dunglas_doctrine_json_odm.normalizer.array', '@serializer.normalizer.datetime', '@dunglas_doctrine_json_odm.normalizer.object']
            - ['@serializer.encoder.json']
        public: true
        autowire: false
<?php

namespace App\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Security\Core\User\UserInterface;

/**
 * @ORM\Entity(repositoryClass="App\Repository\ProUserRepository")
 */
class ProUser implements UserInterface
{
...
    /**
     * @ORM\Column(type="string", nullable=true, length=15)
     * @Assert\Length(allowEmptyString="false", min="5", max="15")
     */
    private $phone;

    /** @ORM\Column(type="string", length=60, nullable=true)
     */
    private $public_mail;

    /**
     * @ORM\Column(type="json_document", options={"jsonb": true}, nullable=true)
     */
    private $document;

...

I can save my object in database but my find request fail.
Capture d’écran 2020-07-14 à 11 12 14
It seems to deserialize is call in JsonDocumentType without passing type :
return $this->getSerializer()->deserialize($value, '', $this->format, $this->deserializationContext);

Do you have an idea about this ? it is a service configuration problem ?

Would be great to share how you solved it. :)

Sorry I don't remember, but I stoped to use this bundle because of serialize problem inherit from PHP.
Today I work with NestJs that offer a serious solution for serialization.

This solved it for me:

services:
    dunglas_doctrine_json_odm.serializer:
-        class: Symfony\Component\Serializer\Serializer
+        class: Dunglas\DoctrineJsonOdm\Serializer
        public: true
        arguments:

This solved it for me:

services:
    dunglas_doctrine_json_odm.serializer:
-        class: Symfony\Component\Serializer\Serializer
+        class: Dunglas\DoctrineJsonOdm\Serializer
        public: true
        arguments:

Yes, switching to the Dunglas Serializer fixed it for me, and I can now serialize / deserialize arrays of objects in my database. Wondering why the Symfony Serializer is incapable of this functionality.