Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DoctrineObjectConstructor fails loading entity when deserializing XML #1286

Closed
jviersel-ipronto opened this issue Feb 19, 2021 · 3 comments
Closed

Comments

@jviersel-ipronto
Copy link
Contributor

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no

When you deserialize XML, the DoctrineObjectConstructor does not retrieve the values in the correct way, causing all values to be NULL, so loading the Doctrine entity fails.

In version 3.11.0 on line 110 of DoctrineObjectConstructor is says:
$identifierList[$name] = $data[$propertyMetadata->serializedName];

But when deserializing XML, $data is not an array; its a SimpleXMLElement. In this case, the value should be retrieved like
$identifierList[$name] = (string)$data->{$propertyMetadata->serializedName}

Suggested fix

if ($data instanceof \SimpleXMLElement) {
    $identifierList[$name] = (string)$data->{$propertyMetadata->serializedName};
} else {
    $identifierList[$name] = $data[$propertyMetadata->serializedName];
}

Steps required to reproduce the problem

  1. Configure your project to use the DoctrineObjectConstructor
  2. Deserialize some XML containing the id into a Doctrine entity
  3. you get an exception because the identifier is missing

Expected Result

  • Loaded Doctrine entity by specified id

Actual Result

  • An exception, because the identifier is missing
@goetas
Copy link
Collaborator

goetas commented Feb 21, 2021

Hmm, that makes sense. Can you create a pull request with a suggested fix (and a test possibly..)?

@jviersel-ipronto
Copy link
Contributor Author

Yes, I can submit a merge request. But now I re-think this solution: is this the right way to solve the problem? Shouldn't $data always be an array (maybe even forced to be an array in the function definition)? Isn't the actual bug in the parser that should return an array instead of an SimpleXmlElement?

jviersel-ipronto added a commit to jviersel-ipronto/serializer that referenced this issue Feb 23, 2021
goetas pushed a commit that referenced this issue Mar 7, 2021
Fix for issue #1286: loading fails when deserializing XML
@goetas
Copy link
Collaborator

goetas commented Mar 7, 2021

fixed by #1289

@goetas goetas closed this as completed Mar 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants