8000 Merge branch '5.4' into 6.3 · symfony/symfony@180e173 · GitHub
[go: up one dir, main page]

Skip to content
Sign in

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 180e173

Browse files
Merge branch '5.4' into 6.3
* 5.4: [Serializer] Revert allowed attributes fix
2 parents a1475d3 + 963cccd commit 180e173

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
@@ -19,7 +19,6 @@
1919
use Symfony\Component\PropertyInfo\Type;
2020
use Symfony\Component\Serializer\Annotation\Context;
2121
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
22-
use Symfony\Component\Serializer\Annotation\Ignore;
2322
use Symfony\Component\Serializer\Annotation\SerializedName;
2423
use Symfony\Component\Serializer\Annotation\SerializedPath;
2524
use Symfony\Component\Serializer\Exception\ExtraAttributesException;
@@ -844,14 +843,6 @@ public function testDenormalizeWithCorrectOrderOfAttributeAndProperty()
844843
$this->assertSame('nested-id', $test->id);
845844
}
846845

847-
public function testNormalizeWithIgnoreAnnotationAndPrivateProperties()
848-
{
849-
$classMetadataFactory = new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader()));
850-
$normalizer = new ObjectNormalizer($classMetadataFactory);
851-
852-
$this->assertSame(['foo' => 'foo'], $normalizer->normalize(new ObjectDummyWithIgnoreAnnotationAndPrivateProperty()));
853-
}
854-
855846
public function testNormalizeBasedOnAllowedAttributes()
856847
{
857848
$normalizer = new class() extends AbstractObjectNormalizer {
@@ -1125,16 +1116,6 @@ class ObjectDummyWithContextAttributeSkipNullValues
11251116
public ?string $propertyWithNullSkipNullValues = null;
11261117
}
11271118

1128-
class ObjectDummyWithIgnoreAnnotationAndPrivateProperty
1129-
{
1130-
public $foo = 'foo';
1131-
1132-
/** @Ignore */
1133-
public $ignored = 'ignored';
1134-
1135-
private $private = 'private';
1136-
}
1137-
11381119
class AbstractObjectNormalizerWithMetadata extends AbstractObjectNormalizer
11391120
{
11401121
public function __construct()

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

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

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

476476
public function testDeserializeAndSerializeNestedInterfacedObjectsWithTheClassMetadataDiscriminator()

0 commit comments

Comments
 (0)
0