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

Serializer throw exception when Ignore attribute is used #49710

Copy link
Copy link
Closed
@ludekbenedik

Description

@ludekbenedik
Issue body actions

Symfony version(s) affected

5.4.21

Description

Hi,
the serializer throws an exception when the Ignore attribute is used and an entity contains a private getter/isser.

How to reproduce

This is OK:

class EntityWithSerializerIgnore
{
    public function getFoo(): int { return 1; }
    public function getBar(): int { return 2; }
    private function isSomething(): bool { return true; }
}

$entity = new EntityWithSerializerIgnore();
$serializer->serialize($entity, 'json'); // {"foo":1,"bar":2}

This throws an exception:

class EntityWithSerializerIgnore
{
    public function getFoo(): int { return 1; }
    #[Ignore]
    public function getBar(): int { return 2; }
    private function isSomething(): bool { return true; }
}

$entity = new EntityWithSerializerIgnore();
$serializer->serialize($entity, 'json'); // throws: Can't get a way to read the property "something" in class "EntityWithSerializerIgnore".

Possible Solution

The AbstractNormalizer::getAllowedAttributes method returns all attributes (public, private) loaded by the AnnotationLoader when the Ignore attribute is used. But the ObjectNormalizer load only public attributes (methods).

The AbstractObjectNormalizer::getAttributes method cannot returns all allowed attributes, but have to combine these attributes with extracted attributes.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.