Skip to content

Wrong Serializer Groups import in Symfony User documentation #8573

Description

@mccoder99

The Symfony User documentation uses the following import for serialization groups:

use Symfony\Component\Serializer\Annotation\Groups;

With API Platform 5.0 and Symfony 8.1, this does not work as shown in the documentation.

The correct import is:

use Symfony\Component\Serializer\Attribute\Groups;

I noticed this because debug:serializer App\Entity\User showed empty serialization groups for all properties when using Annotation\Groups.

After changing the import to Attribute\Groups and clearing the Symfony cache, the serialization groups were correctly detected and the documented user creation endpoint worked as expected.

Environment
API Platform: 5.0
Symfony: 8.1
PHP: 8.4
Expected behavior

The serialization groups shown in the documentation should be recognized when following the example with a current Symfony version.

Actual behavior

Using Symfony\Component\Serializer\Annotation\Groups results in the groups not being recognized by the serializer.

debug:serializer App\Entity\User reports:

email groups => []
plainPassword groups => []

This subsequently causes the documented POST /api/users operation to fail validation because email and plainPassword are not denormalized.

Suggested fix

Update the example to use:

use Symfony\Component\Serializer\Attribute\Groups;

The current serialization documentation already indicates that Symfony 7+ uses attributes, so the User documentation appears to be inconsistent with this.

Activity

  1. added theissue type on Sep 26, 2026
  2. soyuka commented on Sep 28, 2026

    @soyuka
    Member

    You are right, and it is wider than the User doc: the Annotation alias namespace was deprecated in Symfony 7.4 and removed in 8.0, so on your Symfony 8.1 the import resolves to nothing and the attribute never applies, which is exactly the groups => [] you saw.

    Fixed across the documentation in api-platform/docs#2348 — 21 imports in 6 files, covering Groups and Context, the two classes from that namespace the docs reference.

    Thanks for the precise report, the debug:serializer output made it quick to confirm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions