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 4ff9d99

Browse filesBrowse files
committed
[Serializer] Unset attributes when creating child context
1 parent c9f72e2 commit 4ff9d99
Copy full SHA for 4ff9d99

File tree

Expand file treeCollapse file tree

2 files changed

+12
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+12
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,8 @@ protected function createChildContext(array $parentContext, $attribute)
402402
{
403403
if (isset($parentContext[self::ATTRIBUTES][$attribute])) {
404404
$parentContext[self::ATTRIBUTES] = $parentContext[self::ATTRIBUTES][$attribute];
405+
} else {
406+
unset($parentContext[self::ATTRIBUTES]);
405407
}
406408

407409
return $parentContext;

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,16 @@ public function testAttributesContextNormalize()
673673
),
674674
$serializer->normalize($objectDummy, null, $context)
675675
);
676+
677+
$context = array('attributes' => array('foo', 'baz', 'object'));
678+
$this->assertEquals(
679+
array(
680+
'foo' => 'foo',
681+
'baz' => true,
682+
'object' => array('foo' => 'innerFoo', 'bar' => 'innerBar'),
683+
),
684+
$serializer->normalize($objectDummy, null, $context)
685+
);
676686
}
677687

678688
public function testAttributesContextDenormalize()

0 commit comments

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