I use jms serializer (https://jmsyst.com/libs/serializer) outside symfony framework. I had structure of response like that:
[
{ "id": 1 },
{ "id": 2 }
]
When I use
$serializer->deserialize($json, 'ArrayCollection<NAMESPACE/ITEM>', 'json');
it works great and I get ArrayCollection of obects, but I want to wrap it to object of ItemsWrapper which simulates json structure like:
{
"items":
[
{ "id": 1 },
{ "id": 2 }
]
}
I try to do that by add wrapper class with property:
/**
* @Type("ArrayCollection<NAMESPACE/ITEM>")
*/
private $items;
and deseralize like that:
$serializer->deserialize($json, NAMESPACE/ItemsWrapper::class, 'json');
But It doesn’t work I get object ItemsWrapper with null inside items property.
Can I achieve my goal without add listeners/subsribers or deserialize to existing object (https://jmsyst.com/libs/serializer/master/cookbook/object_constructor)??