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 809932d

Browse filesBrowse files
committed
[Serializer] Fix using deserialization path
1 parent 6b8b52d commit 809932d
Copy full SHA for 809932d

File tree

4 files changed

+75
-6
lines changed
Filter options

4 files changed

+75
-6
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
@@ -429,7 +429,7 @@ public function denormalize($data, string $type, string $format = null, array $c
429429
sprintf('Failed to denormalize attribute "%s" value for class "%s": '.$e->getMessage(), $attribute, $type),
430430
$data,
431431
['unknown'],
432-
$context['deserialization_path'] ?? null,
432+
$attributeContext['deserialization_path'] ?? null,
433433
false,
434434
$e->getCode(),
435435
$e

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

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

1188+
/**
1189+
* @requires PHP 7.4
1190+
*/
1191+
public function testCollectDenormalizationErrorsWithoutTypeExtractor()
1192+
{
1193+
$json = '
1194+
{
1195+
"string": [],
1196+
"int": [],
1197+
"float": []
1198+
}';
1199+
1200+
$serializer = new Serializer([new ObjectNormalizer()], ['json' => new JsonEncoder()]);
1201+
1202+
try {
1203+
$serializer->deserialize($json, Php74Full::class, 'json', [
1204+
DenormalizerInterface::COLLECT_DENORMALIZATION_ERRORS => true,
1205+
]);
1206+
1207+
$this->fail();
1208+
} catch (\Throwable $th) {
1209+
$this->assertInstanceOf(PartialDenormalizationException::class, $th);
1210+
}
1211+
1212+
$this->assertInstanceOf(Php74Full::class, $th->getData());
1213+
1214+
$exceptionsAsArray = array_map(function (NotNormalizableValueException $e): array {
1215+
return [
1216+
'currentType' => $e->getCurrentType(),
1217+
'expectedTypes' => $e->getExpectedTypes(),
1218+
'path' => $e->getPath(),
1219+
'useMessageForUser' => $e->canUseMessageForUser(),
1220+
'message' => $e->getMessage(),
1221+
];
1222+
}, $th->getErrors());
1223+
1224+
$expected = [
1225+
[
1226+
'currentType' => 'array',
1227+
'expectedTypes' => [
1228+
'unknown',
1229+
],
1230+
'path' => 'string',
1231+
'useMessageForUser' => false,
1232+
'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".',
1233+
],
1234+
[
1235+
'currentType' => 'array',
1236+
'expectedTypes' => [
1237+
'unknown',
1238+
],
1239+
'path' => 'int',
1240+
'useMessageForUser' => false,
1241+
'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".',
1242+
],
1243+
[
1244+
'currentType' => 'array',
1245+
'expectedTypes' => [
1246+
'unknown',
1247+
],
1248+
'path' => 'float',
1249+
'useMessageForUser' => false,
1250+
'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".',
1251+
],
1252+
];
1253+
1254+
$this->assertSame($expected, $exceptionsAsArray);
1255+
}
1256+
11881257
/**
11891258
* @dataProvider provideCollectDenormalizationErrors
11901259
*
@@ -1240,7 +1309,7 @@ public function testCollectDenormalizationErrorsWithConstructor(?ClassMetadataFa
12401309
'expectedTypes' => [
12411310
'unknown',
12421311
],
1243-
'path' => null,
1312+
'path' => 'string',
12441313
'useMessageForUser' => true,
12451314
'message' => 'Failed to create object because the class misses the "string" property.',
12461315
],
@@ -1249,7 +1318,7 @@ public function testCollectDenormalizationErrorsWithConstructor(?ClassMetadataFa
12491318
'expectedTypes' => [
12501319
'unknown',
12511320
],
1252-
'path' => null,
1321+
'path' => 'int',
12531322
'useMessageForUser' => true,
12541323
'message' => 'Failed to create object because the class misses the "int" property.',
12551324
],

‎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.4|^6.0.4",
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.