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

Appearance settings

Commit 9194fa4

Browse filesBrowse files
committed
[Serializer] Fix using deserialization path
1 parent 10a3cc3 commit 9194fa4
Copy full SHA for 9194fa4

File tree

4 files changed

+77
-8
lines changed
Filter options

4 files changed

+77
-8
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ protected function instantiateObject(array &$data, string $class, array &$contex
414414
sprintf('Failed to create object because the class misses the "%s" property.', $constructorParameter->name),
415415
$data,
416416
['unknown'],
417-
$objectDeserializationPath,
417+
$context['deserialization_path'],
418418
true
419419
);
420420
$context['not_normalizable_value_exceptions'][] = $exception;

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ public function denormalize($data, string $type, string $format = null, array $c
437437
sprintf('Failed to denormalize attribute "%s" value for class "%s": '.$e->getMessage(), $attribute, $type),
438438
$data,
439439
['unknown'],
440-
$context['deserialization_path'] ?? null,
440+
$attributeContext['deserialization_path'] ?? null,
441441
false,
442442
$e->getCode(),
443443
$e

‎src/Symfony/Component/Serializer/Tests/SerializerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/SerializerTest.php
+74-5Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ public function testCollectDenormalizationErrors(?ClassMetadataFactory $classMet
10491049
'expectedTypes' => [
10501050
'unknown',
10511051
],
1052-
'path' => 'php74FullWithConstructor',
1052+
'path' => 'php74FullWithConstructor.constructorArgument',
10531053
'useMessageForUser' => true,
10541054
'message' => 'Failed to create object because the class misses the "constructorArgument" property.',
10551055
],
@@ -1186,6 +1186,75 @@ public function testCollectDenormalizationErrors2(?ClassMetadataFactory $classMe
11861186
$this->assertSame($expected, $exceptionsAsArray);
11871187
}
11881188

1189+
/**
1190+
* @requires PHP 7.4
1191+
*/
1192+
public function testCollectDenormalizationErrorsWithoutTypeExtractor()
1193+
{
1194+
$json = '
1195+
{
1196+
"string": [],
1197+
"int": [],
1198+
"float": []
1199+
}';
1200+
1201+
$serializer = new Serializer([new ObjectNormalizer()], ['json' => new JsonEncoder()]);
1202+
1203+
try {
1204+
$serializer->deserialize($json, Php74Full::class, 'json', [
1205+
DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS => true,
1206+
]);
1207+
1208+
$this->fail();
1209+
} catch (\Throwable $th) {
1210+
$this->assertInstanceOf(PartialDenormalizationException::class, $th);
1211+
}
1212+
1213+
$this->assertInstanceOf(Php74Full::class, $th->getData());
1214+
1215+
$exceptionsAsArray = array_map(function (NotNormalizableValueException $e): array {
1216+
return [
1217+
'currentType' => $e->getCurrentType(),
1218+
'expectedTypes' => $e->getExpectedTypes(),
1219+
'path' => $e->getPath(),
1220+
'useMessageForUser' => $e->canUseMessageForUser(),
1221+
'message' => $e->getMessage(),
1222+
];
1223+
}, $th->getErrors());
1224+
1225+
$expected = [
1226+
[
1227+
'currentType' => 'array',
1228+
'expectedTypes' => [
1229+
'unknown',
1230+
],
1231+
'path' => 'string',
1232+
'useMessageForUser' => false,
1233+
'message' => 'Failed to denormalize attribute "string" value for class "Symfony\\Component\\Serializer\\Tests\\Fixtures\\Php74Full": Expected argument of type "string", "array" given at property path "string".',
1234+
],
1235+
[
1236+
'currentType' => 'array',
1237+
'expectedTypes' => [
1238+
'unknown',
1239+
],
1240+
'path' => 'int',
1241+
'useMessageForUser' => false,
1242+
'message' => 'Failed to denormalize attribute "int" value for class "Symfony\\Component\\Serializer\\Tests\\Fixtures\\Php74Full": Expected argument of type "int", "array" given at property path "int".',
1243+
],
1244+
[
1245+
'currentType' => 'array',
1246+
'expectedTypes' => [
1247+
'unknown',
1248+
],
1249+
'path' => 'float',
1250+
'useMessageForUser' => false,
1251+
'message' => 'Failed to denormalize attribute "float" value for class "Symfony\\Component\\Serializer\\Tests\\Fixtures\\Php74Full": Expected argument of type "float", "array" given at property path "float".',
1252+
],
1253+
];
1254+
1255+
$this->assertSame($expected, $exceptionsAsArray);
1256+
}
1257+
11891258
/**
11901259
* @dataProvider provideCollectDenormalizationErrors
11911260
*
@@ -1241,7 +1310,7 @@ public function testCollectDenormalizationErrorsWithConstructor(?ClassMetadataFa
12411310
'expectedTypes' => [
12421311
'unknown',
12431312
],
1244-
'path' => null,
1313+
'path' => 'string',
12451314
'useMessageForUser' => true,
12461315
'message' => 'Failed to create object because the class misses the "string" property.',
12471316
],
@@ -1250,7 +1319,7 @@ public function testCollectDenormalizationErrorsWithConstructor(?ClassMetadataFa
12501319
'expectedTypes' => [
12511320
'unknown',
12521321
],
1253-
'path' => null,
1322+
'path' => 'int',
12541323
'useMessageForUser' => true,
12551324
'message' => 'Failed to create object because the class misses the "int" property.',
12561325
],
@@ -1300,7 +1369,7 @@ public function testCollectDenormalizationErrorsWithInvalidConstructorTypes()
13001369
[
13011370
'currentType' => 'string',
13021371
'expectedTypes' => [
1303-
0 => 'bool',
1372+
'bool',
13041373
],
13051374
'path' => 'bool',
13061375
'useMessageForUser' => false,
@@ -1309,7 +1378,7 @@ public function testCollectDenormalizationErrorsWithInvalidConstructorTypes()
13091378
[
13101379
'currentType' => 'bool',
13111380
'expectedTypes' => [
1312-
0 => 'int',
1381+
'int',
13131382
],
13141383
'path' => 'int',
13151384
'useMessageForUser' => false,

‎src/Symfony/Component/Serializer/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"symfony/http-foundation": "^4.4|^5.0|^6.0",
3434
"symfony/http-kernel": "^4.4|^5.0|^6.0",
3535
"symfony/mime": "^4.4|^5.0|^6.0",
36-
"symfony/property-access": "^5.4|^6.0",
36+
"symfony/property-access": "^5.4.5|^6.0.5",
3737
"symfony/property-info": "^5.4.24|^6.2.11",
3838
"symfony/uid": "^5.3|^6.0",
3939
"symfony/validator": "^4.4|^5.0|^6.0",

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.