8000 [Serializer] Ignore when using #[Ignore] on a non-accessor · symfony/symfony@580b06a · GitHub
[go: up one dir, main page]

Skip to content

Commit 580b06a

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

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)
0