Skip to content

Navigation Menu

Sign in
Appearance settings

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 22e9fd1

Browse filesBrowse 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
Copy full SHA for 22e9fd1

File tree

2 files changed

+4
-7
lines changed
Filter options

2 files changed

+4
-7
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Mapping/Loader/AnnotationLoader.php
+2-4Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/Mapping/Loader/AnnotationLoaderTestCase.php
+2-3Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.