Skip to content

Commit 754463a

Browse files
[Serializer] Ignore when using #[Ignore] on a non-accessor
1 parent e9a7cb9 commit 754463a

File tree

2 files changed

+2
-7
lines changed

2 files changed

+2
-7
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,6 @@ 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));
143-
}
144-
145141
$attributeMetadata->setIgnore(true);
146142
} elseif ($annotation instanceof Context) {
147143
if (!$accessorOrMutator) {

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