Skip to content

Commit 56cc133

Browse files
Merge branch '7.0' into 7.1
* 7.0: [Serializer] Revert allowed attributes fix
2 parents 11b8038 + 6411a47 commit 56cc133

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
@@ -246,16 +246,20 @@ protected function getAttributes(object $object, ?string $format, array $context
246246
return $this->attributesCache[$key];
247247
}
248248

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

251-
if ($mapping = $this->classDiscriminatorResolver?->getMappingForMappedObject($object)) {
252-
array_unshift($attributes, $mapping->getTypeProperty());
251+
if (false !== $allowedAttributes) {
252+
if ($context['cache_key']) {
253+
$this->attributesCache[$key] = $allowedAttributes;
254+
}
255+
256+
return $allowedAttributes;
253257
}
254258

255-
$allowedAttributes = $this->getAllowedAttributes($object, $context, true);
259+
$attributes = $this->extractAttributes($object, $format, $context);
256260

257-
if (false !== $allowedAttributes) {
258-
$attributes = $attributes ? array_intersect($attributes, $allowedAttributes) : $allowedAttributes;
261+
if ($mapping = $this->classDiscriminatorResolver?->getMappingForMappedObject($object)) {
262+
array_unshift($attributes, $mapping->getTypeProperty());
259263
}
260264

261265
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
@@ -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 {
@@ -1089,16 +1080,6 @@ class ObjectDummyWithContextAttributeSkipNullValues
10891080
public ?string $propertyWithNullSkipNullValues = null;
10901081
}
10911082

1092-
class ObjectDummyWithIgnoreAttributeAndPrivateProperty
1093-
{
1094-
public $foo = 'foo';
1095-
1096-
#[Ignore]
1097-
public $ignored = 'ignored';
1098-
1099-
private $private = 'private';
1100-
}
1101-
11021083
class AbstractObjectNormalizerWithMetadata extends AbstractObjectNormalizer
11031084
{
11041085
public function __construct()

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

Lines changed: 1 addition & 1 deletion
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)