Using Symfony Serializer with Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor
will cause the type of $url
property to be detected incorrectly.
$serializer->deserialize(SomeResponse::class, '{"url": "http://test"}');
We'll get an exception with an error like this:
The type of the "url" attribute for class "SomeResponse" must be one of "bool" ("string" given).
That's because ReflectionExtractor
does this:
public function getTypes(string $class, string $property, array $context = []): ?array
{
if ($fromMutator = $this->extractFromMutator($class, $property)) { // skipped, but will also cause same problem if mutator is present
return $fromMutator;
}
if ($fromAccessor = $this->extractFromAccessor($class, $property)) { // here we go
return $fromAccessor; // data suggesting 'bool' returned before extracting from constructor
}
if (
($context['enable_constructor_extraction'] ?? $this->enableConstructorExtraction)
&& $fromConstructor = $this->extractFromConstructor($class, $property)
) {
return $fromConstructor;
}
if ($fromPropertyDeclaration = $this->extractFromPropertyDeclaration($class, $property)) {
return $fromPropertyDeclaration;
}
return null;
}
That's a bit unexpected, I guess 🤷
Already reported: symfony/symfony#57719