mrMantir
mrMantir

Reputation: 2285

JMSSerializer deserializing collection

I have a problem with deserializing serialized collection of doctrine collections. Couldn't find docs about that and any topics and I'm new with JMSSerializer. When I try deserialize with:

$collection = $serializer->deserialize($jsonData,'Doctrine\Common\Collections\ArrayCollection','json');

$collection is empty

When I set to null instead of class name I have assoc array on result. Is there an elegant way to deserialize that json?

EDIT: Sorry. Here is serialized collection:

[{"id":88,"name":"Poland","created_at":"2012-09-28T11:59:06+0000"},{"id":90,"name":"Great Britain","created_at":"2012-09-28T11:59:06+0000"}]

Upvotes: 18

Views: 9116

Answers (1)

mrMantir
mrMantir

Reputation: 2285

Hah! Found what I done wrong :) I gave to deserialize method wrong type. Should be:

$serializer->deserialize($jsonData, 'ArrayCollection<EntityName>', 'json');

and it gave me beatiful array of entities.

Upvotes: 42

Related Questions