Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"}]
like image 858
mrMantir Avatar asked Oct 01 '12 19:10

mrMantir


People also ask

What is JsonSerializer deserialize?

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.

How do I deserialize an object in .NET core?

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.


1 Answers

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.

like image 193
mrMantir Avatar answered Oct 12 '22 06:10

mrMantir