Serde
Serde copied to clipboard
Enum and StaticTypeMap breaks
Got exception:
Error: Cannot instantiate enum FooAccountEnum in ReflectionClass->newInstanceWithoutConstructor() (line 168 of vendor/crell/serde/src/PropertyHandler/ObjectImporter.php).
from sth like this:
public function __construct(
#[StaticTypeMap(key: 'type', map: [
'foo' => FooAccountEnum::class,
'bar' => BarAccountEnum::class,
])]
public readonly AccountInterface $account,
) {}
Hmm, this is a hard one to work around on my side, it'd involve manually spelling out at least a 5*5 array of typed classes.
Type maps aren't necessary on enums. As long as you're using their backing value in the serialized data, they should "just work."