Skip to content

Use an enum type when looking up the class normalizer of an enum - #240

Merged
DavidBadura merged 1 commit into
2.1.xfrom
enum-class-normalizer
Nov 6, 2026
Merged

DavidBadura merged 1 commit into
2.1.xfrom
enum-class-normalizer

Conversation

@DavidBadura

Copy link
Copy Markdown
Member

getNormalizerOnClass() built the class type with Type::object(), so the guesser never offered the EnumNormalizer for an enum class. extract(Status::Draft) returned ['name' => 'Draft', 'value' => 'draft'], hydrate(Status::class, 'draft') failed, and an #[EnumNormalizer] without an explicit enum on the enum or on an interface it implements failed with a missing type. The class type is now built the way the type resolver builds it for a property.

Things a caller can notice: extracting a backed enum directly now gives its value instead of name and value, and an enum inside an ObjectMapNormalizer now fails on extract instead of producing data that could never be hydrated anyway. Metadata cached with the PSR-6 or PSR-16 factories keeps the old result until the cache is cleared. An enum property with an explicit #[ObjectNormalizer] round-trips once #239 is in as well.

getNormalizerOnClass always built the class type with Type::object(), so the
guesser never saw a BackedEnumType for an enum class and never offered the
EnumNormalizer. Extracting a backed enum directly gave its name and value, and
hydrating it failed. An EnumNormalizer attribute without an explicit enum, on
the enum or on an interface it implements, failed with a missing type for the
same reason. The type is now built the way the type resolver builds it for a
property of that class. An enum property with an explicit ObjectNormalizer
also needs #239 to be hydrated again.
@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown

Hello 👋

Here are the most recent benchmark results, compared against 2.1.x. Time is the mode over the iterations in the its column, with the relative standard deviation in brackets.

StackHydrator

subject revs its memory base current diff
benchHydrate1Object 1000 5 1.856mb -21.21% 1.102μs (±0.16%) 1.128μs (±1.33%) +2.37%
benchExtract1Object 1000 5 1.856mb -21.21% 1.338μs (±1.04%) 1.351μs (±0.84%) +1.03%
benchHydrate1000Objects 3 5 1.856mb -21.21% 1.076ms (±1.55%) 1.108ms (±1.27%) +2.97%
benchExtract1000Objects 3 5 1.856mb -21.21% 1.107ms (±0.74%) 1.113ms (±0.55%) +0.57%

StackHydratorWithCryptography

subject revs its memory base current diff
benchHydrate1Object 1000 5 1.856mb 0.00% 1.727μs (±1.25%) 1.746μs (±1.36%) +1.06%
benchExtract1Object 1000 5 1.856mb 0.00% 4.189μs (±1.07%) 4.112μs (±0.53%) -1.84%
benchHydrate1000Objects 3 5 1.856mb 0.00% 1.682ms (±0.48%) 1.692ms (±1.03%) +0.55%
benchExtract1000Objects 3 5 1.856mb 0.00% 3.895ms (±0.34%) 3.910ms (±0.46%) +0.39%

StackHydratorWithLazy

subject revs its memory base current diff
benchHydrate1Object 1000 5 1.856mb 0.00% 0.174μs (±3.02%) 0.180μs (±7.12%) +3.10%
benchHydrate1ObjectTriggerInit 1000 5 1.856mb 0.00% 1.486μs (±0.64%) 1.476μs (±1.41%) -0.65%
benchHydrate1000Objects 3 5 1.856mb 0.00% 169.594μs (±1.42%) 162.556μs (±2.56%) -4.15%
benchHydrate1000ObjectsTriggerInit 3 5 1.856mb 0.00% 1.461ms (±0.75%) 1.472ms (±0.19%) +0.74%

This comment gets updated every time a new commit comes in.

@DavidBadura DavidBadura added the bug Something isn't working label Nov 6, 2026
@DavidBadura DavidBadura added this to the 2.1.1 milestone Nov 6, 2026
@DavidBadura
DavidBadura merged commit 904bcf3 into 2.1.x Nov 6, 2026
17 checks passed
@DavidBadura
DavidBadura deleted the enum-class-normalizer branch November 6, 2026 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants