bug #14711 [Serializer] AbstractNormalizer instantiateObject avoid null
rejection (boekkooi)
This PR was submitted for the 2.8 branch but it was merged into the 2.7 branch instead (closes #14711).
Discussion
----------
[Serializer] AbstractNormalizer instantiateObject avoid `null` rejection
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
This PR fixes a bug in the AbstractNormalizer when denormalizing a array with a null argument.
Commits
-------
d546080
[Serializer] AbstractNormalizer::instantiateObject avoid `null` rejection
This commit is contained in:
commit
c563bbc2e4
@ -324,7 +324,7 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N
|
||||
|
||||
$allowed = $allowedAttributes === false || in_array($paramName, $allowedAttributes);
|
||||
$ignored = in_array($paramName, $this->ignoredAttributes);
|
||||
if ($allowed && !$ignored && isset($data[$key])) {
|
||||
if ($allowed && !$ignored && array_key_exists($key, $data)) {
|
||||
$params[] = $data[$key];
|
||||
// don't run set for a parameter passed to the constructor
|
||||
unset($data[$key]);
|
||||
|
@ -193,6 +193,16 @@ class GetSetMethodNormalizerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertTrue($obj->isBaz());
|
||||
}
|
||||
|
||||
public function testConstructorDenormalizeWithNullArgument()
|
||||
{
|
||||
$obj = $this->normalizer->denormalize(
|
||||
array('foo' => 'foo', 'bar' => null, 'baz' => true),
|
||||
__NAMESPACE__.'\GetConstructorDummy', 'any');
|
||||
$this->assertEquals('foo', $obj->getFoo());
|
||||
$this->assertNull($obj->getBar());
|
||||
$this->assertTrue($obj->isBaz());
|
||||
}
|
||||
|
||||
public function testConstructorDenormalizeWithMissingOptionalArgument()
|
||||
{
|
||||
$obj = $this->normalizer->denormalize(
|
||||
|
@ -137,6 +137,16 @@ class ObjectNormalizerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertTrue($obj->isBaz());
|
||||
}
|
||||
|
||||
public function testConstructorDenormalizeWithNullArgument()
|
||||
{
|
||||
$obj = $this->normalizer->denormalize(
|
||||
array('foo' => 'foo', 'bar' => null, 'baz' => true),
|
||||
__NAMESPACE__.'\ObjectConstructorDummy', 'any');
|
||||
$this->assertEquals('foo', $obj->getFoo());
|
||||
$this->assertNull($obj->bar);
|
||||
$this->assertTrue($obj->isBaz());
|
||||
}
|
||||
|
||||
public function testConstructorDenormalizeWithMissingOptionalArgument()
|
||||
{
|
||||
$obj = $this->normalizer->denormalize(
|
||||
|
@ -151,6 +151,17 @@ class PropertyNormalizerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('bar', $obj->getBar());
|
||||
}
|
||||
|
||||
public function testConstructorDenormalizeWithNullArgument()
|
||||
{
|
||||
$obj = $this->normalizer->denormalize(
|
||||
array('foo' => null, 'bar' => 'bar'),
|
||||
__NAMESPACE__.'\PropertyConstructorDummy', '
|
||||
any'
|
||||
);
|
||||
$this->assertNull($obj->getFoo());
|
||||
$this->assertEquals('bar', $obj->getBar());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideCallbacks
|
||||
*/
|
||||
|
Reference in New Issue
Block a user