[Serializer] Allow null values when denormalizing with constructor missing data
This commit is contained in:
parent
0615759e7c
commit
5fd0f3f453
@ -378,7 +378,7 @@ abstract class AbstractNormalizer implements NormalizerInterface, DenormalizerIn
|
|||||||
// Don't run set for a parameter passed to the constructor
|
// Don't run set for a parameter passed to the constructor
|
||||||
$params[] = $parameterData;
|
$params[] = $parameterData;
|
||||||
unset($data[$key]);
|
unset($data[$key]);
|
||||||
} elseif (isset($context[static::DEFAULT_CONSTRUCTOR_ARGUMENTS][$class][$key])) {
|
} elseif (array_key_exists($key, $context[static::DEFAULT_CONSTRUCTOR_ARGUMENTS][$class] ?? array())) {
|
||||||
$params[] = $context[static::DEFAULT_CONSTRUCTOR_ARGUMENTS][$class][$key];
|
$params[] = $context[static::DEFAULT_CONSTRUCTOR_ARGUMENTS][$class][$key];
|
||||||
} elseif ($constructorParameter->isDefaultValueAvailable()) {
|
} elseif ($constructorParameter->isDefaultValueAvailable()) {
|
||||||
$params[] = $constructorParameter->getDefaultValue();
|
$params[] = $constructorParameter->getDefaultValue();
|
||||||
|
@ -245,11 +245,11 @@ class ObjectNormalizerTest extends TestCase
|
|||||||
|
|
||||||
$result = $normalizer->denormalize($data, DummyValueObject::class, 'json', array(
|
$result = $normalizer->denormalize($data, DummyValueObject::class, 'json', array(
|
||||||
'default_constructor_arguments' => array(
|
'default_constructor_arguments' => array(
|
||||||
DummyValueObject::class => array('foo' => '', 'bar' => ''),
|
DummyValueObject::class => array('foo' => '', 'bar' => '', 'baz' => null),
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->assertEquals(new DummyValueObject(10, ''), $result);
|
$this->assertEquals(new DummyValueObject(10, '', null), $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGroupsNormalize()
|
public function testGroupsNormalize()
|
||||||
@ -1117,11 +1117,13 @@ class DummyValueObject
|
|||||||
{
|
{
|
||||||
private $foo;
|
private $foo;
|
||||||
private $bar;
|
private $bar;
|
||||||
|
private $baz;
|
||||||
|
|
||||||
public function __construct($foo, $bar)
|
public function __construct($foo, $bar, $baz)
|
||||||
{
|
{
|
||||||
$this->foo = $foo;
|
$this->foo = $foo;
|
||||||
$this->bar = $bar;
|
$this->bar = $bar;
|
||||||
|
$this->baz = $baz;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user