Skip to content

Commit 22e9fd1

Browse files
committed
bug #54485 [Serializer] Ignore when using #[Ignore] on a non-accessor (nicolas-grekas)
This PR was merged into the 5.4 branch. Discussion ---------- [Serializer] Ignore when using #[Ignore] on a non-accessor | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #54477 | License | MIT Because ignore means ignore so we know what to do with the attribute even when it's on something else than an accessor. Commits ------- 580b06a [Serializer] Ignore when using #[Ignore] on a non-accessor
2 parents e88d61e + 580b06a commit 22e9fd1

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

src/Symfony/Component/Serializer/Mapping/Loader/AnnotationLoader.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,9 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata)
138138

139139
$attributeMetadata->setSerializedName($annotation->getSerializedName());
140140
} elseif ($annotation instanceof Ignore) {
141-
if (!$accessorOrMutator) {
142-
throw new MappingException(sprintf('Ignore on "%s::%s()" cannot be added. Ignore can only be added on methods beginning with "get", "is", "has" or "set".', $className, $method->name));
141+
if ($accessorOrMutator) {
142+
$attributeMetadata->setIgnore(true);
143143
}
144-
145-
$attributeMetadata->setIgnore(true);
146144
} elseif ($annotation instanceof Context) {
147145
if (!$accessorOrMutator) {
148146
throw new MappingException(sprintf('Context on "%s::%s()" cannot be added. Context can only be added on methods beginning with "get", "is", "has" or "set".', $className, $method->name));

src/Symfony/Component/Serializer/Tests/Mapping/Loader/AnnotationLoaderTestCase.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,12 @@ public function testCanHandleUnrelatedIgnoredMethods()
141141
{
142142
$class = $this->getNamespace().'\Entity45016';
143143

144-
$this->expectException(MappingException::class);
145-
$this->expectExceptionMessage(sprintf('Ignore on "%s::badIgnore()" cannot be added', $class));
146-
147144
$metadata = new ClassMetadata($class);
148145
$loader = $this->getLoaderForContextMapping();
149146

150147
$loader->loadClassMetadata($metadata);
148+
149+
$this->assertSame(['id'], array_keys($metadata->getAttributesMetadata()));
151150
}
152151

153152
public function testIgnoreGetterWirhRequiredParameterIfIgnoreAnnotationIsUsed()

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