[Serializer] Unset attributes when creating child context

This commit is contained in:
Kévin Dunglas 2017-12-04 17:28:00 +01:00
parent c9f72e2807
commit 4ff9d99f23
No known key found for this signature in database
GPG Key ID: 4D04EBEF06AAF3A6
2 changed files with 12 additions and 0 deletions

View File

@ -402,6 +402,8 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N
{
if (isset($parentContext[self::ATTRIBUTES][$attribute])) {
$parentContext[self::ATTRIBUTES] = $parentContext[self::ATTRIBUTES][$attribute];
} else {
unset($parentContext[self::ATTRIBUTES]);
}
return $parentContext;

View File

@ -673,6 +673,16 @@ class ObjectNormalizerTest extends TestCase
),
$serializer->normalize($objectDummy, null, $context)
);
$context = array('attributes' => array('foo', 'baz', 'object'));
$this->assertEquals(
array(
'foo' => 'foo',
'baz' => true,
'object' => array('foo' => 'innerFoo', 'bar' => 'innerBar'),
),
$serializer->normalize($objectDummy, null, $context)
);
}
public function testAttributesContextDenormalize()