8000 [Serializer] Ignore when using #[Ignore] on a non-accessor by nicolas-grekas · Pull Request #54485 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Serializer] Ignore when using #[Ignore] on a non-accessor #54485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the comm 8000 unity.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,9 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata)

$attributeMetadata->setSerializedName($annotation->getSerializedName());
} elseif ($annotation instanceof Ignore) {
if (!$accessorOrMutator) {
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));
if ($accessorOrMutator) {
$attributeMetadata->setIgnore(true);
}

$attributeMetadata->setIgnore(true);
} elseif ($annotation instanceof Context) {
if (!$accessorOrMutator) {
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,12 @@ public function testCanHandleUnrelatedIgnoredMethods()
{
$class = $this->getNamespace().'\Entity45016';

$this->expectException(MappingException::class);
$this->expectExceptionMessage(sprintf('Ignore on "%s::badIgnore()" cannot be added', $class));

$metadata = new ClassMetadata($class);
$loader = $this->getLoaderForContextMapping();

$loader->loadClassMetadata($metadata);

$this->assertSame(['id'], array_keys($metadata->getAttributesMetadata()));
}

public function testIgnoreGetterWirhRequiredParameterIfIgnoreAnnotationIsUsed()
Expand Down
Loading
0