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"}]
Serialization and deserialization in . NET application, JSON data format conversion to . NET objects and vice versa is very common. Serialization is the process of converting . NET objects such as strings into a JSON format and deserialization is the process of converting JSON data into . NET objects.
NET objects (deserialize) A common way to deserialize JSON is to first create a class with properties and fields that represent one or more of the JSON properties. Then, to deserialize from a string or a file, call the JsonSerializer. Deserialize method.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With