[Serializer] AbstractNormalizer::instantiateObject avoid null
rejection
This commit is contained in:
parent
58efb98c6f
commit
d546080d20
@ -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