2

I am using Doctrine-ODM and I'm trying to (de)serialize document Objects in Symfony.

The serialization seems to work, but when I try to deserialize I get the following error:

You must define a type for My\Bundle\Repository\Item::$id.

I try to deserialize with this call:

$object = $serializer->deserialize($serializedItem, 'My\Bundle\Repository\Item', 'json');

My document has a few Embedded Documents but they seem to be okay in the serialized String. It is missing Information about the Document-Type. Here a simplified example of the output:

{
    id: "itemID",
    - embededDocument: {
        id: "embeddedDocumentID",
        moreInformation: true
    }
}

now I have read the usage instructions and I assume that my solution is explained in the metadata for third party cookbook, but I can't figure out what to do.

How do I fix that and deserialize my Strings to Objects properly?

j0k
  • 22,600
  • 28
  • 79
  • 90
Senči
  • 911
  • 2
  • 10
  • 25

1 Answers1

1

In My\Bundle\Repository\Item, you need to define an id property, and decorate it with the @Type annotation.

greg0ire
  • 22,714
  • 16
  • 72
  • 101