How to POST on 3 level with JSONLD & Hydra (Symfony API)

443 views Asked by At

I'm actually working on a Symfony REST API and doing some tests for a further project and I need your help.

I have an Entity Contact, which have an array of MoyenCommunication (abstract class with only an id). I have en Entity Telephone, which inherits from MoyenCommunication and contains a unique property "numero".

 Contact -> ($moyenComms)[Telephone->numero]

I'd like to test my API and add directly a Contact with a MoyenCommunication that is Telephone with it's "numero".

Here is the Json-LD I try to post :

{
"nom": "Nomgfdg",
"prenom": "Prenomgfdgd",
"dateNaissance": "2016-02-16",
"amiDepuis": "2016-02-16",
"moyensComm": [
    {
        "@type": "Telephone",
        "numero": "100009"
     }
     ]
}

Here is the Response :

 Cannot create an instance of ContactBundle\\Entity\\MoyenCommunication from serialized data because it is an abstract resource

Here is my MoyenCommunication mapping :

    inheritanceType: JOINED
discriminatorColumn:
    name: type
    type: integer
discriminatorMap:
    1: Telephone

I really don't know what i'm doing bad so I need your help. I already googled but without any good result. Thank you. Boris

1

There are 1 answers

7
Paweł Mikołajczuk On

Error is pretty clear:

Cannot create an instance of ContactBundle\Entity\MoyenCommunication from serialized data because it is an abstract resource

You need to use non abstract class for resource. Create new class witch will extend MoyenCommunication and use it for your resource representation.