Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 963cccd

Browse filesBrowse files
bug #52786 [Serializer] Revert allowed attributes fix (mtarld)
This PR was merged into the 5.4 branch. Discussion ---------- [Serializer] Revert allowed attributes fix | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | | License | MIT Revert #52767 and #52680, as it does not cover some specific use cases, and can't be fixed in time. I'll attempt to fix it in a better way, taking more time. Commits ------- 1dc20a8 [Serializer] Revert allowed attributes fix
2 parents 0fe7090 + 1dc20a8 commit 963cccd
Copy full SHA for 963cccd

File tree

3 files changed

+11
-26
lines changed
Filter options

3 files changed

+11
-26
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/AbstractObjectNormalizer.php
+10-6Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/Normalizer/AbstractObjectNormalizerTest.php
-19Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/SerializerTest.php
+1-1Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.