serializer
serializer copied to clipboard
DoctrineObjectConstructor Error undefined index id
Hi JMS,
I got issue when deserialize JSON, these lines of code throw an exception `foreach ($classMetadata->getIdentifierFieldNames() as $name) { if ($visitor instanceof AbstractVisitor) { /** @var PropertyNamingStrategyInterface $namingStrategy */ $namingStrategy = $visitor->getNamingStrategy(); $dataName = $namingStrategy->translateName($metadata->propertyMetadata[$name]); } else { $dataName = $name; }
if (!array_key_exists($dataName, $data)) {
return $this->fallbackConstructor->construct($visitor, $metadata, $data, $type, $context);
}
$identifierList[$name] = $data[$dataName];
}`
Since I don't add the annotation before the identify field:
- @JMS\Expose
- @JMS\Groups({"inspection-report", "audit-report"})
So, Do we have to add it before identify fields?
Thanks!
I have the same issue and I don't think this invalid.
It will happen when we have a entity that does't expose it's primary key. (For example a entity that can only be created but never updated or get).
Just a extra if would do the job since those line that are already present will take care of the rest:
if (!array_key_exists($dataName, $data)) { return $this->fallbackConstructor->construct($visitor, $metadata, $data, $type, $context); }
I am facing the same issue. @mpoiriert @ngocongcan Did you guys find a workaround?