Skip to content

Commit d04ef91

Browse files
Merge branch '6.3' into 6.4
* 6.3: [Serializer] Revert allowed attributes fix
2 parents 8abe7fe + 180e173 commit d04ef91

File tree

3 files changed

+11
-26
lines changed

3 files changed

+11
-26
lines changed

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

+10-6
Original file line numberDiff line numberDiff line change
@@ -260,16 +260,20 @@ protected function getAttributes(object $object, ?string $format, array $context
260260
return $this->attributesCache[$key];
261261
}
262262

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

265-
if ($mapping = $this->classDiscriminatorResolver?->getMappingForMappedObject($object)) {
266-
array_unshift($attributes, $mapping->getTypeProperty());
265+
if (false !== $allowedAttributes) {
266+
if ($context['cache_key']) {
267+
$this->attributesCache[$key] = $allowedAttributes;
268+
}
269+
270+
return $allowedAttributes;
267271
}
268272

269-
$allowedAttributes = $this->getAllowedAttributes($object, $context, true);
273+
$attributes = $this->extractAttributes($object, $format, $context);
270274

271-
if (false !== $allowedAttributes) {
272-
$attributes = $attributes ? array_intersect($attributes, $allowedAttributes) : $allowedAttributes;
275+
if ($mapping = $this->classDiscriminatorResolver?->getMappingForMappedObject($object)) {
276+
array_unshift($attributes, $mapping->getTypeProperty());
273277
}
274278

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

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

-19
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Symfony\Component\PropertyInfo\Type;
1919
use Symfony\Component\Serializer\Attribute\Context;
2020
use Symfony\Component\Serializer\Attribute\DiscriminatorMap;
21-
use Symfony\Component\Serializer\Attribute\Ignore;
2221
use Symfony\Component\Serializer\Attribute\SerializedName;
2322
use Symfony\Component\Serializer\Attribute\SerializedPath;
2423
use Symfony\Component\Serializer\Exception\ExtraAttributesException;
@@ -837,14 +836,6 @@ public function testDenormalizeWithCorrectOrderOfAttributeAndProperty()
837836
$this->assertSame('nested-id', $test->id);
838837
}
839838

840-
public function testNormalizeWithIgnoreAttributeAndPrivateProperties()
841-
{
842-
$classMetadataFactory = new ClassMetadataFactory(new AttributeLoader());
843-
$normalizer = new ObjectNormalizer($classMetadataFactory);
844-
845-
$this->assertSame(['foo' => 'foo'], $normalizer->normalize(new ObjectDummyWithIgnoreAttributeAndPrivateProperty()));
846-
}
847-
848839
public function testNormalizeBasedOnAllowedAttributes()
849840
{
850841
$normalizer = new class() extends AbstractObjectNormalizer {
@@ -1084,16 +1075,6 @@ class ObjectDummyWithContextAttributeSkipNullValues
10841075
public ?string $propertyWithNullSkipNullValues = null;
10851076
}
10861077

1087-
class ObjectDummyWithIgnoreAttributeAndPrivateProperty
1088-
{
1089-
public $foo = 'foo';
1090-
1091-
#[Ignore]
1092-
public $ignored = 'ignored';
1093-
1094-
private $private = 'private';
1095-
}
1096-
10971078
class AbstractObjectNormalizerWithMetadata extends AbstractObjectNormalizer
10981079
{
10991080
public function __construct()

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ public function testDeserializeAndSerializeInterfacedObjectsWithTheClassMetadata
469469
'groups' => ['two'],
470470
]);
471471

472-
$this->assertEquals('{"type":"one","two":2}', $serialized);
472+
$this->assertEquals('{"two":2,"type":"one"}', $serialized);
473473
}
474474

475475
public function testDeserializeAndSerializeNestedInterfacedObjectsWithTheClassMetadataDiscriminator()

0 commit comments

Comments
 (0)