Skip to content

Commit 1dc20a8

Browse files
committed
[Serializer] Revert allowed attributes fix
1 parent 0fe7090 commit 1dc20a8

File tree

3 files changed

+11
-26
lines changed

3 files changed

+11
-26
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,16 +309,20 @@ protected function getAttributes(object $object, ?string $format, array $context
309309
return $this->attributesCache[$key];
310310
}
311311

312-
$attributes = $this->extractAttributes($object, $format, $context);
312+
$allowedAttributes = $this->getAllowedAttributes($object, $context, true);
313313

314-
if ($this->classDiscriminatorResolver && $mapping = $this->classDiscriminatorResolver->getMappingForMappedObject($object)) {
315-
array_unshift($attributes, $mapping->getTypeProperty());
314+
if (false !== $allowedAttributes) {
315+
if ($context['cache_key']) {
316+
$this->attributesCache[$key] = $allowedAttributes;
317+
}
318+
319+
return $allowedAttributes;
316320
}
317321

318-
$allowedAttributes = $this->getAllowedAttributes($object, $context, true);
322+
$attributes = $this->extractAttributes($object, $format, $context);
319323

320-
if (false !== $allowedAttributes) {
321-
$attributes = $attributes ? array_intersect($attributes, $allowedAttributes) : $allowedAttributes;
324+
if ($this->classDiscriminatorResolver && $mapping = $this->classDiscriminatorResolver->getMappingForMappedObject($object)) {
325+
array_unshift($attributes, $mapping->getTypeProperty());
322326
}
323327

324328
if ($context['cache_key'] && \stdClass::class !== $class) {

src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor;
1818
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
1919
use Symfony\Component\PropertyInfo\Type;
20-
use Symfony\Component\Serializer\Annotation\Ignore;
2120
use Symfony\Component\Serializer\Exception\ExtraAttributesException;
2221
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
2322
use Symfony\Component\Serializer\Exception\LogicException;
@@ -455,14 +454,6 @@ public function testNormalizeEmptyObject()
455454
$this->assertEquals(new \ArrayObject(), $normalizedData);
456455
}
457456

458-
public function testNormalizeWithIgnoreAnnotationAndPrivateProperties()
459-
{
460-
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
461-
$normalizer = new ObjectNormalizer($classMetadataFactory);
462-
463-
$this->assertSame(['foo' => 'foo'], $normalizer->normalize(new ObjectDummyWithIgnoreAnnotationAndPrivateProperty()));
464-
}
465-
466457
public function testNormalizeBasedOnAllowedAttributes()
467458
{
468459
$normalizer = new class() extends AbstractObjectNormalizer {
@@ -586,16 +577,6 @@ class EmptyDummy
586577
{
587578
}
588579

589-
class ObjectDummyWithIgnoreAnnotationAndPrivateProperty
590-
{
591-
public $foo = 'foo';
592-
593-
/** @Ignore */
594-
public $ignored = 'ignored';
595-
596-
private $private = 'private';
597-
}
598-
599580
class AbstractObjectNormalizerWithMetadata extends AbstractObjectNormalizer
600581
{
601582
public function __construct()

src/Symfony/Component/Serializer/Tests/SerializerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ public function testDeserializeAndSerializeInterfacedObjectsWithTheClassMetadata
473473
'groups' => ['two'],
474474
]);
475475

476-
$this->assertEquals('{"type":"one","two":2}', $serialized);
476+
$this->assertEquals('{"two":2,"type":"one"}', $serialized);
477477
}
478478

479479
public function testDeserializeAndSerializeNestedInterfacedObjectsWithTheClassMetadataDiscriminator()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy