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 the StringTypeResolver
/ TypeContext
:
The use is not respected here, and therefore this returns the wrong full class of App\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,
) {}
}