prevent mixup of the object to populate
This commit is contained in:
parent
c82e2df9ff
commit
fdb668e051
@ -330,6 +330,8 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N
|
|||||||
|
|
||||||
return $object;
|
return $object;
|
||||||
}
|
}
|
||||||
|
// clean up even if no match
|
||||||
|
unset($context[static::OBJECT_TO_POPULATE]);
|
||||||
|
|
||||||
$constructor = $this->getConstructor($data, $class, $context, $reflectionClass, $allowedAttributes);
|
$constructor = $this->getConstructor($data, $class, $context, $reflectionClass, $allowedAttributes);
|
||||||
if ($constructor) {
|
if ($constructor) {
|
||||||
|
@ -315,6 +315,30 @@ class ObjectNormalizerTest extends TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testObjectToPopulateNoMatch()
|
||||||
|
{
|
||||||
|
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
|
||||||
|
$this->normalizer = new ObjectNormalizer($classMetadataFactory, null, null, new PhpDocExtractor());
|
||||||
|
new Serializer([$this->normalizer]);
|
||||||
|
|
||||||
|
$objectToPopulate = new ObjectInner();
|
||||||
|
$objectToPopulate->foo = 'foo';
|
||||||
|
|
||||||
|
$outer = $this->normalizer->denormalize([
|
||||||
|
'foo' => 'foo',
|
||||||
|
'inner' => [
|
||||||
|
'bar' => 'bar',
|
||||||
|
],
|
||||||
|
], ObjectOuter::class, null, [ObjectNormalizer::OBJECT_TO_POPULATE => $objectToPopulate]);
|
||||||
|
|
||||||
|
$this->assertInstanceOf(ObjectOuter::class, $outer);
|
||||||
|
$inner = $outer->getInner();
|
||||||
|
$this->assertInstanceOf(ObjectInner::class, $inner);
|
||||||
|
$this->assertNotSame($objectToPopulate, $inner);
|
||||||
|
$this->assertSame('bar', $inner->bar);
|
||||||
|
$this->assertNull($inner->foo);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider provideCallbacks
|
* @dataProvider provideCallbacks
|
||||||
*/
|
*/
|
||||||
@ -936,6 +960,9 @@ class ObjectOuter
|
|||||||
{
|
{
|
||||||
public $foo;
|
public $foo;
|
||||||
public $bar;
|
public $bar;
|
||||||
|
/**
|
||||||
|
* @var ObjectInner
|
||||||
|
*/
|
||||||
private $inner;
|
private $inner;
|
||||||
private $date;
|
private $date;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user