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 67f49d4

Browse filesBrowse files
committed
Fix order array sum normalizedData and nestedData
Previously, when `array_merge` was changed array+array in 6.3.5, the combined array result is changed as well. array_merge behaves differently than array+array. e.g.: ``` $a = ['key' => 'value-a']; $b = ['key' => 'value-b']; var_dump(array_merge($a, $b)); // Results in: // array(1) { // ["key"]=> // string(7) "value-b" // } var_dump($a + $b); // Results in: // array(1) { // ["key"]=> // string(7) "value-a" // } ``` By switching left with right, the result will be the same again.
1 parent 7aa60d6 commit 67f49d4
Copy full SHA for 67f49d4

File tree

2 files changed

+23
-1
lines changed
Filter options

2 files changed

+23
-1
lines changed

‎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
@@ -339,7 +339,7 @@ public function denormalize(mixed $data, string $type, string $format = null, ar
339339
$normalizedData = $this->removeNestedValue($serializedPath->getElements(), $normalizedData);
340340
}
341341

342-
$normalizedData = $normalizedData + $nestedData;
342+
$normalizedData = $nestedData + $normalizedData;
343343

344344
$object = $this->instantiateObject($normalizedData, $mappedClass, $context, new \ReflectionClass($mappedClass), $allowedAttributes, $format);
345345
$resolvedClass = ($this->objectClassResolver)($object);

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,28 @@ public function testDenormalizeWithNumberAsSerializedNameAndNoArrayReindex()
813813
$this->assertSame('foo', $test->foo);
814814
$this->assertSame('baz', $test->baz);
815815
}
816+
817+
public function testDenormalizeWithCorrectOrderOfAttributeAndProperty()
818+
{
819+
$normalizer = new AbstractObjectNormalizerWithMetadata();
820+
821+
$data = [
822+
'id' => 'root-level-id',
823+
'data' => [
824+
'id' => 'nested-id',
825+
],
826+
];
827+
828+
$obj = new class() {
829+
/**
830+
* @SerializedPath("[data][id]")
831+
*/
832+
public $id;
833+
};
834+
835+
$test = $normalizer->denormalize($data, $obj::class);
836+
$this->assertSame('nested-id', $test->id);
837+
}
816838
}
817839

818840
class AbstractObjectNormalizerDummy extends AbstractObjectNormalizer

0 commit comments

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