8000 [Serializer] Unset attributes when creating child context · symfony/symfony@4ff9d99 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4ff9d99

Browse files
committed
[Serializer] Unset attributes when creating child context
1 parent c9f72e2 commit 4ff9d99

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

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

Lines 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

Lines 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