8000 [Serializer] Object attributes are cached when there are attributes and groups fields in context · Issue #25444 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Serializer] Object attributes are cached when there are attributes and groups fields in context #25444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
baptadn opened this issue Dec 11, 2017 · 2 comments

Comments

@baptadn
Copy link
baptadn commented Dec 11, 2017
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'
     )
 )
@baptadn baptadn changed the title [Serializer] Attributes are cached with attributes and groups in context [Serializer] Object attributes are cached when there are attributes and groups fields in context Dec 11, 2017
@Simperfit
Copy link
Contributor

Do you want to work on this bug ?

@sroze
Copy link
Contributor
sroze commented Jan 15, 2018

This has been fixed by #25185, right?

@xabbuh xabbuh closed this as completed Jan 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants
0