Closed
Description
Q | A |
---|---|
Bug report | yes |
Feature request | no |
BC Break report | no |
RFC | no |
Symfony version | 3.3.14 |
Issue related to #25185
With group context filled, attributes are cached even if there is the attributes
within context. Steps to reproduce (based on this test):
Add groups annotations:
class ObjectOuter
{
/**
* @Groups({"api"})
*/
public $foo;
/**
* @Groups({"api"})
*/
public $bar;
}
class ObjectInner
{
/**
* @Groups({"api"})
*/
public $foo;
/**
* @Groups({"api"})
*/
public $bar;
}
Add groups within context:
public function testNormalizeSameObjectWithDifferentAttributes()
{
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
$this->normalizer = new ObjectNormalizer($classMetadataFactory);
$serializer = new Serializer(array($this->normalizer));
$this->normalizer->setSerializer($serializer);
$dummy = new ObjectOuter();
$dummy->foo = new ObjectInner();
$dummy->foo->foo = 'foo.foo';
$dummy->foo->bar = 'foo.bar';
$dummy->bar = new ObjectInner();
$dummy->bar->foo = 'bar.foo';
$dummy->bar->bar = 'bar.bar';
$this->assertEquals(array(
'foo' => array(
'bar' => 'foo.bar',
),
'bar' => array(
'foo' => 'bar.foo',
),
), $this->normalizer->normalize($dummy, 'json', array(
'groups' => ['api'],
'attributes' => array(
'foo' => array('bar'),
'bar' => array('foo'),
),
)));
}
Result:
1) Symfony\Component\Serializer\Tests\Normalizer\ObjectNormalizerTest::testNormalizeSameObjectWithDifferentAttributes
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
Array (
'foo' => Array (...)
'bar' => Array (
- 'foo' => 'bar.foo'
+ 'bar' => 'bar.bar'
)
)