You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bug #54913 [Serializer] Fix CurrentType for missing property (ElisDN)
This PR was merged into the 5.4 branch.
Discussion
----------
[Serializer] Fix CurrentType for missing property
| Q | A
| ------------- | ---
| Branch? | 5.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Issues |
| License | MIT
If requested data does not contain any property:
```php
class A {
function __construct(string $a) {}
}
try {
$a = $serializer->deserialize('{}', A::class, 'json');
} catch (NotNormalizableValueException $e) {
var_dump($e->getMessage()); // "Failed to create object because class misses the 'a' property."
var_dump($e->getPath()); // "a"
var_dump($e->getExpectedTypes()); // ["string"]
var_dump($e->getCurrentType()); // "array"
}
```
then `getCurrentType` returns incorrect `"array"` value instead of expected `"null"` value.
Commits
-------
5de8771 [Serializer] Fix type for missing property
Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/SerializerTest.php
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -1045,7 +1045,7 @@ public function testCollectDenormalizationErrors(?ClassMetadataFactory $classMet
1045
1045
'message' => 'The type of the "string" attribute for class "Symfony\Component\Serializer\Tests\Fixtures\Php74Full" must be one of "string" ("null" given).',
1046
1046
],
1047
1047
[
1048
-
'currentType' => 'array',
1048
+
'currentType' => 'null',
1049
1049
'expectedTypes' => [
1050
1050
'unknown',
1051
1051
],
@@ -1306,7 +1306,7 @@ public function testCollectDenormalizationErrorsWithConstructor(?ClassMetadataFa
1306
1306
'message' => 'The type of the "bool" attribute for class "Symfony\\Component\\Serializer\\Tests\\Fixtures\\Php80WithPromotedTypedConstructor" must be one of "bool" ("string" given).',
1307
1307
],
1308
1308
[
1309
-
'currentType' => 'array',
1309
+
'currentType' => 'null',
1310
1310
'expectedTypes' => [
1311
1311
'string',
1312
1312
],
@@ -1315,7 +1315,7 @@ public function testCollectDenormalizationErrorsWithConstructor(?ClassMetadataFa
1315
1315
'message' => 'Failed to create object because the class misses the "string" property.',
1316
1316
],
1317
1317
[
1318
-
'currentType' => 'array',
1318
+
'currentType' => 'null',
1319
1319
'expectedTypes' => [
1320
1320
'int',
1321
1321
],
@@ -1420,7 +1420,7 @@ public function testCollectDenormalizationErrorsWithEnumConstructor()
1420
1420
1421
1421
$expected = [
1422
1422
[
1423
-
'currentType' => 'array',
1423
+
'currentType' => 'null',
1424
1424
'useMessageForUser' => true,
1425
1425
'message' => 'Failed to create object because the class misses the "get" property.',
1426
1426
],
@@ -1546,7 +1546,7 @@ public function testPartialDenormalizationWithMissingConstructorTypes()
0 commit comments