Skip to content

Conversation

@mdeboer
Copy link
Contributor

@mdeboer mdeboer commented Nov 29, 2025

Q A
Branch? 8.1
Bug fix? no
New feature? yes
Deprecations? no
Issues
License MIT

This PR stems from a discussion I had with @xabbuh following the discussion at #54226 and specifically the comment from @nesl247.

With this PR I would like to propose some changes in the BackedEnumNormalizer that give the exception messages a bit more meaning in terms of what data is actually expected.

Example

Before

enum StringBackedEnumDummy: string
{
    case GET = 'GET';
    case OPTIONS = 'OPTIONS';
}

$this->normalizer->denormalize('POST', StringBackedEnumDummy::class);

// Throws NotNormalizableValueException with message:
//   The data must belong to a backed enumeration of type StringBackedEnumDummy

After

enum StringBackedEnumDummy: string
{
    case GET = 'GET';
    case OPTIONS = 'OPTIONS';
}

$this->normalizer->denormalize('POST', StringBackedEnumDummy::class);

// Throws NotNormalizableValueException with message:
//   The data must be one of the following values: 'GET', 'OPTIONS'

Improves the message when throwing the NotNormalizableValueException in the BackedEnumNormalizer. It gives better feedback what value type is expected (matching the backed type of the enum) and if the type is correct, what values are expected.
@mdeboer mdeboer marked this pull request as ready for review November 29, 2025 13:45
@mdeboer mdeboer requested a review from dunglas as a code owner November 29, 2025 13:45
@carsonbot carsonbot added this to the 8.1 milestone Nov 29, 2025
Copy link
Member

@fabpot fabpot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense to me.

@OskarStark OskarStark changed the title [Serializer] Improve NotNormalizableValueException exception messages in BackedEnumNormalizer [Serializer] Improve NotNormalizableValueException exception messages in BackedEnumNormalizer Nov 29, 2025
@symfony symfony deleted a comment from carsonbot Dec 1, 2025
Co-authored-by: Alexandre Daubois <2144837+alexandre-daubois@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants