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

Commit27d9eff

Browse files
ThomasNunningernicolas-grekas
authored andcommitted
[Serializer] Fix AbstractObjectNormalizer not considering pseudo type false
1 parentb460e07 commit27d9eff

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,10 @@ private function validateAndDenormalize(string $currentClass, string $attribute,
537537
return (float)$data;
538538
}
539539

540+
if (Type::BUILTIN_TYPE_FALSE ===$builtinType &&false ===$data) {
541+
return$data;
542+
}
543+
540544
if (('is_'.$builtinType)($data)) {
541545
return$data;
542546
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
useSymfony\Component\Serializer\Tests\Normalizer\Features\ObjectToPopulateTestTrait;
5151
useSymfony\Component\Serializer\Tests\Normalizer\Features\SkipNullValuesTestTrait;
5252
useSymfony\Component\Serializer\Tests\Normalizer\Features\TypeEnforcementTestTrait;
53+
useSymfony\Component\Serializer\Tests\Php80Dummy;
5354

5455
/**
5556
* @author Kévin Dunglas <dunglas@gmail.com>
@@ -699,6 +700,25 @@ public function testExtractAttributesRespectsContext()
699700
$this->assertSame(['foo' =>'bar','bar' =>'foo'],$normalizer->normalize($data,null, ['include_foo_and_bar' =>true]));
700701
}
701702

703+
/**
704+
* @requires PHP 8
705+
*/
706+
publicfunctiontestDenormalizeFalsePseudoType()
707+
{
708+
// given a serializer that extracts the attribute types of an object via ReflectionExtractor
709+
$propertyTypeExtractor =newPropertyInfoExtractor([], [newReflectionExtractor()], [], [], []);
710+
$objectNormalizer =newObjectNormalizer(null,null,null,$propertyTypeExtractor);
711+
712+
$serializer =newSerializer([$objectNormalizer]);
713+
714+
// when denormalizing some data into an object where an attribute uses the false pseudo type
715+
/** @var Php80Dummy $object */
716+
$object =$serializer->denormalize(['canBeFalseOrString' =>false], Php80Dummy::class);
717+
718+
// then the attribute that declared false was filled correctly
719+
$this->assertFalse($object->canBeFalseOrString);
720+
}
721+
702722
publicfunctiontestAdvancedNameConverter()
703723
{
704724
$nameConverter =newclass()implements AdvancedNameConverterInterface {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespaceSymfony\Component\Serializer\Tests;
15+
16+
finalclass Php80Dummy
17+
{
18+
publicfalse|string$canBeFalseOrString;
19+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp