8000 4.1 by voodoo-dn · Pull Request #27816 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

4.1 #27816

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

Closed
wants to merge 3 commits into from
Closed

4.1 #27816

Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Merge attributes from discriminator map only for abstact classes or i…
…nterface
  • Loading branch information
lazer committed Jul 2, 2018
commit c958c86bfa12711d2772a77dc1e0b77b41bd4c9c
22 changes: 16 additions & 6 deletions src/Symfony/Component/Serializer/Normalizer/ObjectNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,24 @@ protected function getAllowedAttributes($classOrObject, array $context, $attribu
return false;
}

if (null !== $this->classDiscriminatorResolver && null !== $discriminatorMapping = $this->classDiscriminatorResolver->getMappingForMappedObject($classOrObject)) {
$allowedAttributes[] = $attributesAsString ? $discriminatorMapping->getTypeProperty() : new AttributeMetadata($discriminatorMapping->getTypeProperty());
$discriminatorMapping = $this->classDiscriminatorResolver ? $this->classDiscriminatorResolver->getMappingForMappedObject($classOrObject) : null;

foreach ($discriminatorMapping->getTypesMapping() as $class) {
$allowedAttributes = array_merge($allowedAttributes, parent::getAllowedAttributes($class, $context, $attributesAsString));
}
if (!$discriminatorMapping) {
return $allowedAttributes;
}

$allowedAttributes[] = $attributesAsString ? $discriminatorMapping->getTypeProperty() : new AttributeMetadata($discriminatorMapping->getTypeProperty());

$reflectionClass = new \ReflectionClass($classOrObject);

if (!$reflectionClass->isAbstract() && !$reflectionClass->isInterface()) {
return $allowedAttributes;
}

foreach ($discriminatorMapping->getTypesMapping() as $class) {
$allowedAttributes = \array_merge($allowedAttributes, parent::getAllowedAttributes($class, $context, $attributesAsString));
}

return $allowedAttributes;
return \array_unique($allowedAttributes);
}
}
0