Skip to content

Commit 4a79bdd

Browse files
committed
do not try to infer discriminator mapping if object to populate is already populated
1 parent 6e9e907 commit 4a79bdd

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/Serializer/AbstractItemNormalizer.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,12 @@ public function denormalize($data, $class, $format = null, array $context = [])
185185
*/
186186
protected function instantiateObject(array &$data, $class, array &$context, \ReflectionClass $reflectionClass, $allowedAttributes, string $format = null)
187187
{
188+
if (null !== $object = $this->extractObjectToPopulate($class, $context, static::OBJECT_TO_POPULATE)) {
189+
unset($context[static::OBJECT_TO_POPULATE]);
190+
191+
return $object;
192+
}
193+
188194
if ($this->classDiscriminatorResolver && $mapping = $this->classDiscriminatorResolver->getMappingForClass($class)) {
189195
if (!isset($data[$mapping->getTypeProperty()])) {
190196
throw new RuntimeException(sprintf('Type property "%s" not found for the abstract object "%s"', $mapping->getTypeProperty(), $class));
@@ -199,12 +205,6 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
199205
$reflectionClass = new \ReflectionClass($class);
200206
}
201207

202-
if (null !== $object = $this->extractObjectToPopulate($class, $context, static::OBJECT_TO_POPULATE)) {
203-
unset($context[static::OBJECT_TO_POPULATE]);
204-
205-
return $object;
206-
}
207-
208208
$constructor = $this->getConstructor($data, $class, $context, $reflectionClass, $allowedAttributes);
209209
if ($constructor) {
210210
$constructorParameters = $constructor->getParameters();

0 commit comments

Comments
 (0)