Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitca5b64d

Browse files
committed
bug#29076 [Serializer] Allow null values when denormalizing with constructor missing data (danut007ro)
This PR was squashed before being merged into the 4.1 branch (closes#29076).Discussion----------[Serializer] Allow null values when denormalizing with constructor missing data| Q | A| ------------- | ---| Branch? | 4.1| Bug fix? | yes| New feature? | no| BC breaks? | no| Deprecations? | no| Tests pass? | yes| License | MITWhen using `default_constructor_arguments` to denormalize objects, `null` values for a parameter weren't processed, so instantiating was failing.Commits-------5fd0f3f [Serializer] Allow null values when denormalizing with constructor missing data
2 parents097963f +5fd0f3f commitca5b64d

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

‎src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ protected function instantiateObject(array &$data, $class, array &$context, \Ref
378378
// Don't run set for a parameter passed to the constructor
379379
$params[] =$parameterData;
380380
unset($data[$key]);
381-
}elseif (isset($context[static::DEFAULT_CONSTRUCTOR_ARGUMENTS][$class][$key])) {
381+
}elseif (array_key_exists($key,$context[static::DEFAULT_CONSTRUCTOR_ARGUMENTS][$class] ??array())) {
382382
$params[] =$context[static::DEFAULT_CONSTRUCTOR_ARGUMENTS][$class][$key];
383383
}elseif ($constructorParameter->isDefaultValueAvailable()) {
384384
$params[] =$constructorParameter->getDefaultValue();

‎src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,11 @@ public function testFillWithEmptyDataWhenMissingData()
245245

246246
$result =$normalizer->denormalize($data, DummyValueObject::class,'json',array(
247247
'default_constructor_arguments' =>array(
248-
DummyValueObject::class =>array('foo' =>'','bar' =>''),
248+
DummyValueObject::class =>array('foo' =>'','bar' =>'','baz' =>null),
249249
),
250250
));
251251

252-
$this->assertEquals(newDummyValueObject(10,''),$result);
252+
$this->assertEquals(newDummyValueObject(10,'',null),$result);
253253
}
254254

255255
publicfunctiontestGroupsNormalize()
@@ -1117,11 +1117,13 @@ class DummyValueObject
11171117
{
11181118
private$foo;
11191119
private$bar;
1120+
private$baz;
11201121

1121-
publicfunction__construct($foo,$bar)
1122+
publicfunction__construct($foo,$bar,$baz)
11221123
{
11231124
$this->foo =$foo;
11241125
$this->bar =$bar;
1126+
$this->baz =$baz;
11251127
}
11261128
}
11271129

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp