Closed marius-dev closed 7 years ago
Did you add $this->property = new Collection();
to your __constructor? You have to initialize your properties first.
I'm pretty sure I've initialized all the collections. The problem arises on ManuToMany relationships, where each entity contains a collection of the other entity type. To avoid "circular reference problem" at serialization I create a normalizer like tihis:
class Normalizer extends ObjectNormalizer { public function __construct(ClassMetadataFactoryInterface $classMetadataFactory = null, NameConverterInterface $nameConverter = null, PropertyAccessorInterface $propertyAccessor = null, PropertyTypeExtractorInterface $propertyTypeExtractor = null) { parent::__construct($classMetadataFactory, $nameConverter, $propertyAccessor, $propertyTypeExtractor); $this->setCircularReferenceHandler(function ($object) { return $object->getId(); }); } }
After one layer, this Normalizer replece the reference to it's id.
I don;t know it that is the problem.
would you be able to provide a link to a test ?
I'm trying to serialize a collection of objects taken from db and get the following error:
Each object is made up of several objects and object collections. What could be the problem?