Skip to content

Support Symfony 8.1 BackendEnumDenormalizer new error #7893

@vincentchalamon

Description

@vincentchalamon

API Platform version(s) affected: x.y.z

Description
Symfony PR #62574 (commit 35b1aec) improves BackedEnumNormalizer error messages. This change was:

  1. Merged to 8.1 branch (Dec 2025)
  2. Accidentally cherry-picked into 8.0.5 — which broke this demo (see PR #587 comment)
  3. Reworked in 8.0.6 (commit 388c311) — the expectedTypes = null behavior was removed from 8.0.x
  4. The demo jumped from v8.0.4 → v8.0.7, skipping the broken v8.0.5

On the current Symfony 8.1 branch, BackedEnumNormalizer distinguishes:

  • Type mismatch (TypeError): expectedTypes = [$backingType]
  • Invalid value (ValueError): expectedTypes = ['int', 'string'], message = "The data must belong to a backed enumeration of type $type"

How to reproduce
Symfony has modified its behavior for BackendEnumDenormalizer in Symfony 8.1. This change is not supported by API Platform and may cause troubles on later migration.
Reproducer: api-platform/demo#617

Possible Solution
Support both Symfony 8.0 and 8.1 behaviors.

Additional Context
PR in progress...

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions