You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm having a bit of an issue after migrating from annotations to attributes in the sense that I have a class such as
<?php
declare(strict_types=1);
namespace App\Tests\Services\SerializeObjects;
use Doctrine\Common\Collections\ArrayCollection;
use JMS\Serializer\Annotation as JMS;
class TestList
{
#[JMS\Type('integer')]
#[JMS\SerializedName('item')]
private int $item;
#[JMS\Type('Doctrine\Common\Collections\ArrayCollection<App\Tests\Services\SerializeObjects\TestObject>')]
#[JMS\SerializedName('list')]
private ArrayCollection $testObjects;
public function __construct()
{
$this->item = 2;
$this->testObjects = new ArrayCollection([
new TestObject(),
new TestObject(),
]);
}
/**
* Get the value of item
*/
public function getItem(): int
{
return $this->item;
}
/**
* Get the value of testObjects
*/
public function getTestObjects(): ArrayCollection
{
return $this->testObjects;
}
}
when I call serialize on this, list becomes a JSON object that contains an elements array which contains the actual TestObject representations. If I use attributes, it works as expected (eg: list is a JSON array of TestObject representations). It seems that the attributes behavior is different somehow in a way that's not documented.
Now, my problem seems to go away if I manually register the ArrayCollectionHandler with the handler registry, though I was under the impression that the built-in handlers don't need to be manually registered (the docs says that the custom ones do).
Is this something lacking in the docs ?
The text was updated successfully, but these errors were encountered:
Hello,
I'm having a bit of an issue after migrating from annotations to attributes in the sense that I have a class such as
when I call serialize on this,
list
becomes a JSON object that contains anelements
array which contains the actual TestObject representations. If I use attributes, it works as expected (eg:list
is a JSON array of TestObject representations). It seems that the attributes behavior is different somehow in a way that's not documented.How the serializer is created:
Now, my problem seems to go away if I manually register the
ArrayCollectionHandler
with the handler registry, though I was under the impression that the built-in handlers don't need to be manually registered (the docs says that the custom ones do).Is this something lacking in the docs ?
The text was updated successfully, but these errors were encountered: