Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
Closed
Description
Symfony version(s) affected
7.2.x
Description
Trying to deserialize some DTO that receives an enum-array as parameter in the constructor. That enum is defined in a different namespace then the DTO. The type is annotated in the doc block.
How to reproduce
Setup
namespace App\AuthServer\Aggregate\AuthApp;use App\AuthServer\Entity\OAuth\Scope;class ClientCreated{ /** * @param Scope[] $scopes */ public function __construct( public readonly array $scopes, ) {}}
namespace App\AuthServer\Entity\OAuth;enum Scope: string{ case OPENID = 'openid';}
Call
$data = '{"scopes": ["openid"]}'serializer->deserialize($data, ClientCreated::class, 'json');
Different variations fail as well (e.g.list<Scope>
).
Possible Solution
I traced this down to theStringTypeResolver
/TypeContext
:
The use is not respected here, and therefore this returns the wrong full class ofApp\AuthServer\Aggregate\AuthApp\Scope
Additional Context
Using the FQCN in the docblock works:
class ClientCreated{ /** * @param \App\AuthServer\Entity\OAuth\Scope[] $scopes */ public function __construct( public readonly array $scopes, ) {}}