schmittjoh / serializer

Library for (de-)serializing data of any complexity (supports JSON, and XML)
http://jmsyst.com/libs/serializer
MIT License
2.32k stars 589 forks source link

Unable to deseriablize #988

Open ngocongcan opened 6 years ago

ngocongcan commented 6 years ago
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no

Steps required to reproduce the problem

  1. Do not add JMS/Annotation before identify field of entity
  2. De serialize JSON

Expected Result

Actual Result

Suggestion

Why we remove check isset($metadata->propertyMetadata[$name]) before access it on v1.13.0 ? It causes error on the project which was using v1.11.0 (still checking ) Now, once updating we have to add the annotation before all identify fields. Could we add isset($metadata->propertyMetadata[$name]) before accessing on DoctrineObjectConstructor?

Thanks!

goetas commented 6 years ago

can you please add more details? like the full exception, your class code and your json document that caused the error.

ngocongcan commented 6 years ago

Thanks for your response. I think you can check line 79 of class DoctrineObjectConstructor $dataName = $namingStrategy->translateName($metadata->propertyMetadata[$name]); There is no check if $metadata->propertyMetadata[$name] exist.

goetas commented 6 years ago

can you please add more details? like the full exception, your class code and your json document that caused the error.

hokkaido commented 6 years ago

The problem is on line 79. This is from 1.13:

    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];
    }

If there is no name present in doctrine's column annotation it might trigger an error at $metadata->propertyMetadata[$name].

In my case, it is triggered when using the DoctrineObjectConstructor with the ObjectConstructor fallback strategy and a custom IdGenerator. Probably not relevant however.